Web Controls
A control is an object that can be drawn on to the Web Form to enable or enhance user interaction with the application. Examples of these controls include the TextBoxes,Buttons, Labels, Radio Buttons etc. All these Web server controls are based on the System.Web.UI.Control class and the class hierarchy is as follows:
Object
Control
Object
Control
Notable properties of the Control objects are summarized in the table below:
Property | Description |
ClientID | Gets the ASP.NET control identifier for the control |
Controls | Gets a collection of child controls in a control |
EnableViewState | Gets/Sets whether the control maintains it's state between server round trips |
ID | Gets/Sets the ID for the control |
Page | Gets the page object that contains the control |
Parent | Gets the control parent control |
Site | Gets the control's Web site |
UniqueID | Gets the Unique ID for the control |
Visible | Gets/Sets whether the control is visible or not |
The WebControl Class
Web server controls in ASP.NET are not based directly on the Control class but are based on the WebControl class, which is based on the Control class. The class hierarchy for the WebControl class is as follows:
Object
Control
WebControl
Object
Control
WebControl
Notable properties of the WebControl class are summarized in the table below:
Property | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
AccessKey | Gets/Sets the access key for the control | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Attributes | Gets a collection of attributes used to render the control | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BackColor | Gets/Sets the control's background color | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BorderColor | Gets/Sets the controls border color | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BorderStyle | Gets/Sets the control's border style | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
BorderWidth | Gets/Sets the control's border width | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ControlStyle | Gets the control's style | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
CssClass | Gets/Sets the control's CSS class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Enabled | Gets/Sets whether the control is enabled | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Font | Gets/Sets the font for the control | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ForeColor | Gets/Sets the control's foreground color | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Height | Gets/Sets the control's height | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Style | Gets the HTML style of the control as a collection of text attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
TabIndex | Gets/Sets the control's tab index | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ToolTip | Gets/Sets the control's tool tip text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Width | Gets/Sets the control's width Label The Label Web Server control is used to label other parts of the application. They are used to display text which the user can't change. To display text on a label we use thetext property. The class hierarchy for this control is as follows: Object Control WebControl Label A label control with BorderStyle property as solid and BorderColor property as blue is shown below. I am Label Literal A Literal Web Server control doesn't have any visual appearance on a Web Form but is used to insert literal text into a Web Form. This control makes it possible to add HTML code directly in the code designer window without switching to design view and clicking the HTML button to edit the HTML. The class hierarchy for this control is as follows: Object Control Literal The notable property of this control is the text property which is the text that is inserted into the Web Form. A literal control with text "I am Literal" is displayed below. I am Literal Editing HTML with Literal Control As mentioned above, we can use a literal control to edit the HTML directly in the code designer. The following line of code demonstrates that.
To test the above line of code click the button below. The text "I am Literal" displayed beside the Button will be underlined and will be displayed in bold format. The difference is we added HTML code directly in the code designer window instead of switching and editing it in HTML view. Live Code Demo I am Literal TextBox The TextBox Web Server control is used to accept input from the user. They appear like a box and allows the user to enter some text, like, username, password, etc. The class hierarchy for this control is as follows: Object Control WebControl TextBox Below is a ReadOnly TextBox with BackColor property set to Silver, BorderColor property set to Brown and BorderStyle property set to solid. Notable properties Notable properties of the TextBox control are as follows: AutoPostBack: Gets/Sets whether events will be automatically posted to the server Columns: Gets/Sets the textbox's width in columns MaxLength: Gets/Sets the maximum number of characters that can be displayed in the textbox ReadOnly: Gets/Sets whether the textbox is readonly Rows: Gets/Sets a multiline textbox's display height Text: Gets/Sets the text in a textbox TextMode: Gets/Sets whether a textbox should be single line, multiline or a password control Wrap: Gets/Sets whether text wraps in a textbox Code Examples Sample 1 Drag a TextBox and a Button control onto the WebForm. When you click the button some text is displayed in a TextBox. The code for that looks like this:
Sample2, Multiline TextBox Drag a TextBox, Button and a Label control onto the form. We will make this TextBox a Multiline textbox and display the text entered in this multiline textbox on a label. Before you proceed, select the textbox, open it's properties window and set it's TextMode property to Multiline. The code to achieve the desired functionality looks like this:
Sample3, Password Character Drag a Textbox, Button and a Label control onto the form. Select the textbox, open it's properties window and set the TextMode property to Password. When you set TextMode property to password, the text you enter in the textbox is masked with asteriks (*). The following code displays the text you entered in the textbox as text for the label.
Live Code Demo Sample1 Buttons A Button Web Server control is a control which we click and release to perform some action. The class hierarchy for the Button control is as follows: Object Control WebControl Button Button Event The default event of the Button is the Click event which looks like this in code:
Notable Properties CausesValidation: Gets/Sets the button that causes validation CommandArgument: Gets/Sets the command argument which is passed to the command event handler CommandName: Gets/Sets the command name which is passed to the command event handler Text: Gets/Sets the caption on the button Command Button To create a command button you need to add a command name to the button. You add a command name to the button with the CommandName property and a commandargument with the CommandArgument property. Both these properties can hold text which can be recovered in code. Sample Code1 Drag a Button onto the form from the toolbox and set it's text as ClickMe. When you click the button it changes it's text from ClickMe to "You clicked Me". The code for that looks like this:
Sample code to create a Command Button Drag two TextBoxes and Buttons from the toolbox. Select Button one and in it's properties window set the CommandName property to Command1 and CommandArgumentproperty to I am Command one. Repeat the same for Button two. When you click Button1, the CommandName of Button1 will be displayed in TextBox1 and CommandArgument of Button2 in TextBox2. To get those values we need to use the command event for the button and not the click event. The code for that looks like this:
Live Code Demo Sample 1 Link Button The LinkButton Web server control is a hyperlink style button control. It looks like a hyperlink control but is actually a button control with click and command events. The class hierarchy for this control is as follows: Object Control WebControl LinkButton Below is a LinkButton Web server control. I am a LinkButton Notable Properties Below are some notable properties of the LinkButton control. CausesValidation: Gets/Sets whether the link button performs validation in other controls CommandArgument: Gets/Sets an optional argument holding data about the command specified with CommandName CommandName: Gets/Sets the command name for this button Text: Gets/Sets the text displayed in the link button Sample Drag a LinkButton and a Label control on to the Web Form. When you click the link button the label displays some text. The code for that looks like this:
HyperLink Control The HyperLink Web server control is used to create a link to another Web page. The text in the HyperLink control is specified using the Text property. We can also display a image on this control instead of text. To display an image we should set the ImageUrl property. If both the Text and ImageUrl properties are set, the ImageUrl property takes precedence. If the image is unavailable, the text in the Text property is displayed. The class hierarchy for this control is as follows: Object Control WebControl HyperLink Notable Properties Below are some notable properties of the Hyperlink control. ImageUrl: Gets/Sets the image to be displayed in the hyperlink NavigateUrl: Gets/Sets the URL to navigate to when the hyperlink is clicked Target: Gets/Sets the target window or frame to display the new content when the hyperlink is clicked Text: Gets/Sets the text in the hyperlink control Note the target property. You can set the target property to the values displayed below. The target property allows us to set new page/content to be displayed in a new browser window, same window, etc. The values are as follows: _blank: displays the linked content in a new window without frames _parent: displays the linked content in the immediate frameset parent _self: displays the linked content in the frame with focus _top: displays the linked content in the full window without frames Sample Drag a hyperlink control on to the form. Select the control and open it's properties window. From the properties window set the NavigateUrl property to your favorite website (in the form http://www.xyz.com), Target property to _blank and Text property to some text. When you run the application and click the hyperlink your favourit website opens in a new window. Live Code Demo LinkButton Sample Label LinkButton Hyperlink Sample My Favourite Site Image The Image Web server control is used to display an image on a Web page. To set the image to be displayed for this control we use the ImageUrl property. The class hierarchy for this control is as follows: Object Control WebControl Image Look at the sample at the bottom of this page for a demo. The ImageButton Web server control is used to display images and responds to mouse clicks on the image. The class hierarchy for this control is as follows: Object Control WebControl Image ImageButton To set the Image for this control we use the ImageUrl property. Image buttons support both Click and Command events. When we handle Click events, we are passed the actual location of the mouse in the image. We can use Command event handlers to make the image button work like a command button. Sample Drag a Label and an ImageButton Control on to the form and paste the following code:
When you run the code and click on the image button, the X and Y coordinates are displayed on the label. Live Code Demo DropDownList The DropDownList Web server control is same as the ListBox control but it supports only single selection and displays items in a drop-down manner. The class hierarchy for this control is as follows: Object Control WebControl ListControl DropDownList DropDownList Event The default event of the drop-down list is the SelectedIndexChanged which looks like this in code:
Notable property of the drop-down list is the Items property with which we add items to the control. Like ListBoxes this control doesn't support multiple selections. DropDownList Sample Drag a DropDownList, Button and a TextBox control on to the form. Add some items to the DropDownList control using it's Item property. The following code will display the item selected from the drop-down list in a textbox when the button is clicked.
Live Code Demo ListBox The ListBox Web server control displays a list of items from which we can make a selection. We can select one or more items from the list of items displayed. The class hierarchy for this control is as follows: Object Control WebControl ListControl ListBox ListBox Event The default event of the list box is the SelectedIndexChanged which looks like this is code:
Notable Properties of the ListBox are as follows: Items: Gets/Sets the collection of items in the control Rows: Gets/Sets the number of rows in the list box SelectionMode: Gets/Sets the list box's selection mode, can be set to single or multiple ListBox Samples Single Selection ListBox Drag a ListBox, Button and a TextBox control on to the form. Add some items to the ListBox using the Items property. The following lines of code will display the item you select from the list box in a textbox when the button is clicked.
Multiple Selection ListBox Modifying the above sample to make the ListBox allow us to select multiple items, select the ListBox and in it's properties window set the SelectionMode proeprty to Multiple. The following lines of code will display the selected items in the textbox when the button is clicked:
Live Code Demo Single Selection ListBox Multiple Selection Listbox CheckBox The CheckBox Web server control gives us an option to select, say, yes/no or true/false. A checkbox is clicked to select and clicked again to deselect some option. When a checkbox is selected, a check (a tick mark) appears indicating a selection. The class hierarchy for this control is as follows: Object Control WebControl CheckBox CheckBox Event The default event of the CheckBox is the CheckedChanged event which looks like this in code:
Notable Properties Notable properties of the CheckBox are as follows: Checked: Gets/Sets whether a checkbox displays a check Text: Gets/Sets the text caption for the checkbox TextAlign: Gets/Sets the alignment of the text caption CheckBox Sample Drag two CheckBoxes, a TextBox and a Button control on to the form. Set the Text property for the CheckBoxes as Male and Female. The following code will display the text of the Checkbox that is checked in the textbox when the button is clicked.
CheckBoxList The CheckBoxList Web server control displays a number of checkboxes at once. This control provides a multi selection check box group that can be dynamically generated with data binding. It contains an Items collection with members that correspond to individual items in the list. To determine which items are checked, we need to test the Selected property of each item in the list. The class hierarchy for his control is as follows: Object Control WebControl ListControl CheckBoxList Notable Properties Notable properties of the CheckBoxList control are as follows: Items: Gets/Sets the collection of items in the list RepeatColumns: Gets/Sets the number of displayed columns in the check box list RepeatDirection: Gets/Sets the display direction of checkboxes RepeatLayout: Gets/Sets the checkbox layout TextAlign: Gets/Sets the check box's text alignment CheckBoxList Sample Drag a CheckBoxList, TextBox and a Button on to the form. Select the CheckBoxList and add some items to it using the Items property. The following code will display the text of the checkbox that is checked in the textbox when the button is clicked.
Live Code Demo CheckBox Sample RadioButtonList The RadioButtonList Web server control is used to display a list of radio buttons. This control provides us with a single-selection radio button group that can be dynamically generated via data binding. The Items property of this control allows us to add items to the control. To determine which item is selected, we need to test the SelectedItem property of the list. The class hierarchy of this control is as follows: Object Control WebControl ListControl RadioButtonList RadioButtonList event The default event of the RadioButtonList is the SelectedIndexChanged which looks like this in code:
Notable Properties Notable properties of the RadioButtonList control are as follows: Items: Gets/Sets the collection of items in the list RepeatColumns: Gets/Sets the number of displayed columns in the radio button list RepeatDirection: Gets/Sets the display direction of radio buttons RepeatLayout: Gets/Sets the radio button layout TextAlign: Gets/Sets the radio button's text alignment RadioButtonListSample Drag a RadioButonList, TextBox and a Buton control on to a form. Add some items to the radio button list with it's item property. The following code will display the item you select in the radio button list in the textbox when you click the button.
Live Code Demo RadioButtonList with 12 items and RepeatColumns property value 4 Select one from the list and hit the submit button RadioButton The RadioButton Web server control is similar to CheckBox but RadioButtons are displayed as rounded instead of box. The class hierarchy for this control is as follows: Object Control WebControl CheckBox Radiobutton Radiobutton Event The default event of the RadioButton is the CheckedChanged event which looks like this in code:
Notable property of the RadioButton control is the GroupName property which sets the radio button's group. The radio button will act in concert with the other members of the group. RadioButton Sample Drag three radio button's, a textbox and a button on to the form. Select each radio button and set the GroupName property for each to ABC. If you do not set the GroupName property to a common name then each radio button will act differently and when you make a selection all radio buttons will be rounded. In most cases, you want your users to select only one option from a given list and to accompolish that you need to set the GroupName property. The following code will display the text of the radio button selected in a textbox when the button is clicked. Select each radio button and set the Text as shown below and paste the following code:
Live Code Demo RadioButtons with no GroupName When you make a selection all radio buttons can be selected RadioButton Sample Demo How did you hear about us? Panel The Panel Web server control is used to contain other controls, say a set of radio buttons, check boxes, etc. This is a very useful control which allows us to show or hide a group of controls at once or add new controls to a page in code. The class hierarchy for this control is as follows: Object Control WebControl Panel Notable Properties Notable properties of the Panel are as follows: BackImageUrl: Gets/Sets the background image's URL for the panel HorizontalAlign: Gets/Sets the horizontal alignment of the parent's contents Wrap: Gets/Sets whether the panel's content wraps Panel Sample Drag a Panel on to the form. Drag two textboxes and a button on to the panel. The following code does nothing special but demonstrates how to use panels. The code displays the text you enter in textbox1 in textbox2 when the button is clicked.
PlaceHolder The PlaceHolder Web server control does not have any visible output and is used as a place holder when we add controls at run time. The class hierarchy for this control is as follows: Object Control PlaceHolder PlaceHolder Sample Drag a PlaceHolder control on to the form. The following code will create two TextBoxes and a Button in code and will add them to the place holder at run time when a button is clicked. Open the code behind file for the web form and paste the following code:
Live Code Demo Panel Demo Place Holder Demo Calendar The Calendar Web server control displays a single month calendar that allows the user to select a date and move to the next or previous month. By default, this control displays the name of the current month, day headings for the days of the weeks, days of the month and arrow characters for navigation to the previuos or next month. The class hierarchy for this control is as follows: Object Control WebControl Calendar Calendar Event The default event of the Calendar control is the SelectionChanged event which looks like this in code:
Notable properties Notable properties of this control that set it's style are as follows: DayHeaderStyle: Sets style for the days of the week DayStyle: Sets styles for the dates in a month NextPrevStyle: Sets style for the navigation controls OtherMonthStyle: Sets style for the dates that are not in the displayed month SelectedDayStyle: Sets style for the selected date SelectorStyle: Sets style for the for week and month selection column TitleStyle: Sets style for the title TodayDayStyle: Sets style for today's date WeekendDayStyle: Sets style for weekend dates In addition to the properties mentioned above there are some more properties than can be set to control different parts of the calendar. They are as follows: ShowDayHeader: Shows or hides the days of the week ShowGridLines: Shows or hides grid lines ShowNextPrevMonth: Shows or hides the navigation controls to the next or previous month ShowTitle: Shows or hides the title Other properties are as follows: CellPadding: Gets/Sets the space used for cell padding in the calendar CellSpacing: Gets/Sets the space between cells in the calendar DayNameFormat: Gets/Sets the day of the week's name format FirstDayOfWeek: Gets/Sets the day of the week displayed in the first column NextMonthText: Gets/Sets the text for next month navigation control NextPrevFormat: Gets/Sets the format for the next and previous month navigation controls OtherMonthDayStyle: Gets the style for the days not displyed in current month PrevMonthText: Gets/Sets the text for previous month navigation control SelectedDate: Gets/Sets the selected date SelectedDates: Gets a collection of DateTime objects for the selected dates SelectionMode: Gets/Sets the date selection mode determining if you can select a day, a week, or a month SelectMonthText: Gets/Sets the text for the month selection element SelectWeekText: Gets/Sets the text for week selection element TitleFormat: Gets/Sets the format for the title TodaysDate: Gets/Sets today's date VisibleDate: Gets/Sets a date making sure it's visible Calendar Sample Drag a Calendar and a TextBox control on to the form. The following code will display the date selected from the Calendar control in the TextBox. The code looks like this:
You can test the above sample below. Live Code Demo
The AdRotator is a special control in ASP.NET that is used to display flashing banner ads. The control is capable of displaying ads randomly or sequentially as set by the user. Each time the page is refreshed or reloaded a new ad can be displayed to the user. Also, we can assign priorities in such a way that certain ads are displayed frequently than others. The class hierarchy for this control is as follows: Object Control WebControl AdRotator Notable properties of the AdRotator control are as follows: AdvertisementFile KeywordFilter Target AdvertisementFile The AdvertisementFile property specifies the path to an Advertisement File. The Advertisement file is a well-formed XML document that contains information for the image that needs to be displayed and the page to which the user should be redirected when he clicks the ad. The syntax for the Advertisement file is as follows:
The different elements of the Advertisement File: ImageUrl: Specifies the image URL that presents the image for the advertisement NavigateUrl: Specifies the URL of the page to which the user should be taken to when he clicks on the image AlternateText: An optional parameter that specifies the text when the user moves his mouse pointer over the image Keyword: Optional parameter that specifies the keyword (category) like books, programming, etc Impressions: Optional parameter that provides a number that indicates the weight of the ad in the order of rotation with respect to other ads in the file KeywordFilter The KeywordFilter property specifies a keyword to filter for specific types of advertisements in the XML advertisement file. Each advertisement in the XML advertisement file can be assigned a category keyword. The KeywordFilter property filters the advertisements for the specified keyword. Only advertisements containing the keyword will be selected for the AdRotator control and it is not possible to specify more than one keyword in the KeywordFilter property, nor it is possible to declare multiple keywords in the advertisement file. Target The Target property specifies the name of the browser window or frame that displays the contents of the Web page linked to when the AdRotator control is clicked. This property can also take the following HTML frame-related keywords. _blank: displays the linked content in a new window without frames _parent: displays the linked content in the parent window of the window that contains the link _self: displays the linked content in the same window _top: displays the linked content in the topmost window Table The Table Web server control allows us to build an HTML table and helps us organize data in a tabular form. Tables can be created at design time or run time. To create a table we also need the TableRow and TableCell web controls. If you create a table at design time you often fill it's contents with static data but if you create it at run time then you can fill it with dynamic content like binding it to a data source. The class hierarchy for this control is as follows: Object Control WebControl Table Notable Properties Notable properties of the Table control are as follows: CellPadding: Gets/Sets the distance between the border and the contents of the table cell CellSpacing: Gets/Sets the distance between table cells GridLines: Gets/Sets the gridline property of the table class HorizontalAlign: Gets/Sets the horizontal alignment of the table within the page Rows: Gets/Sets the collection of rows within the table TableRow Control The TableRow class is used to create the table rows we use in the Table control. It controls how the contents of the table are displayed. The class hierarchy for this control is as follows: Object Control WebControl TableRow Notable Properties Notable properties of the TableRow class are as follows: Cells: Gets a collection of the table cells for the table row HorizontalAlign: Gets/Sets the horizontal alignment of the row contents VerticalAlign: Gets/Sets the vertical alignment of the row contents TableCell Control The TableCell class represents a cell in the Table contol. We use the Text property to set the contents of the cell. The class hierarchy for this control is as follows: Object Control WebControl TableCell Notable Properties Notable proeprties of the TableCell class are as follows: ColumnSpan: Gets/Sets the number of columns the cell spans HorizontalAlign: Gets/Sets the cell content's horizontal alignment RowSpan: Gets/Sets the number of rows the cell spans Text: Gets/Sets the text in the cell VerticalAlign: Gets/Sets the cell content's vertical alignment Wrap: Gets/Sets whether the cell content wraps Creating Tables Creating a table at design time is fairly simple. Drag a table control on to the form and add some rows and columns to it using the Rows property. When you click the ellipsebutton in the Rows property it opens the TableRow Collection Editor window as shown in the image below. You need to click the Add button found on this dialog to add rows to the table. Once you add a row to the table you can notice the properties for the newly added row in the right column of the TableRow Collection Editor window. You can set properties for the row in this column. To add a cell to a row, select the row and click the ellipse button found in the Cells property to open the TableCell Collection EditorWindow. You need to click the Add button found on this window to add cells to the row. Once you add a cell to the row you can notice the properties of the newly added row in the right column of the TableCell Collection Editor window. You can add any number of cells to a row depending upon your requirements. You can view a table at work below. Live Demo
Validation is the process of making sure that the user enters correct information into a form. Validation controls provided by .NET Framework work in the client browser if the browser supports Javascript and DHTML and checks the data the user entered before sending it to the server. All the validation takes place in the browser and nothing is sent back to the server. If the browser doesn't support DHTML and scripting then validation is done on the server. All validation controls in the .NET Framework are derived from the BaseValidator class. This class serves as the base abstract class for the validation controls and provides the implementation for all validation controls that derive from this class. The validation controls that are provided by the .NET Framework are as follows: RequiredFieldValidator CompareValidator RangeValidator RegularExpressionValidator CustomValidator Common to all the above said controls are the ErrorMessage and ControlToValidate properties. The ErrorMessage property is used to set an error to be displayed and the ControlToValidate property is used to set the control you want to check. RequiredFieldValidator Simplest of all, the RequiredField validator makes sure that the user enters data into a form. For example, on a registration form you might want your users to enter their date of birth in a textbox. If they leave this field empty, this validation control will display an error. The class hierarchy for this control is as follows: Object Control WebControl Label BaseValidator RequiredFieldValidator Notable property of the RequiredFieldValidator is the InitialValue property which sets an initial value in the control. CompareValidator Comparison validators are used to compare the values entered by the user into a control (textbox) with the value entered into another control or with a constant value. We indicate the control to validate by setting the ControlToValidate property and if we want to compare a specific control with another control we need to set theControlToCompare property to specify the control to compare with. The class hierarchy for this control is as follows: Object Control WebControl Label BaseValidator BaseCompareValidator CompareValidator RangeValidator Range Validators are used to test if the value of a control is inside a specified range of values. The three main properties of this control are the ControlToValidate property which contains the control to validate and Maximum and Minimum values which hold the maximum and minimum values of the valid range. The class hierarchy for this control is as follows: Object Control WebControl Label BaseValidator BaseCompareValidator RangeValidator RegularExpressionValidator RegularExpression validators are used to check if the value in a control matches a pattern defined by the regular expression. Notable property for this control is theValidationExpression property which allows us to select a predefined expression which we want to match with the data entered in a control. The class hierarchy for this control is as follows: Object Control WebControl Label BaseValidator RegularExpressionValidator CustomValidator Custom validators are used to perform our own validation for the data in a control. For example, you can check the value entered by a user is even or odd with this control which is not possible with any of the above mentioned validation controls. You write the script for the validation using Javascript or VBScript and associate that script function to the ClientValidationFunction property of this control. The class hierarchy for this control is as follows: Object Control WebControl Label BaseValidator CustomValidator ValidationSummary Validation summary control is used to display a summary of all validation errors (from all validation controls) on a Web page. This class is supported by theValidationSummary class and the hierarchy is as follows: Object Control WebControl ValidationSummary Notable property of this control is the DisplayMode property which allows us to display the errors in a specific format, example, as a list, paragraph or as a bulletlist. |
No comments:
Post a Comment