The class ancestor to the web controls is called WebControl. WebControl is used to lay a common foundation to the controls on a web page.
To create a web control, you can drag it from the Toolbox and drop it on a form of a web page. To manually create a web control, you start with a tag as follows:
In this case, replace Web-Control to the class name of the control. Because this is presented like an HTML tag, you must close it. You have two options. You can close the tag as done in traditional HTML:
Alternatively, you can use the starting tag to close itself. The formula is:
<asp:Web Control />
Because they belong to the same ancestor, most, if not all web controls share some characteristics.
The behavior of a control is managed by the server that specify its characteristics. To make this possible, you must indicate this when you add a control.
If you visually add a control, it automatically receives an attribute named runat and whose value is server. If you are manually creating a control, to specify this characteristic, add runat="server" to its list of attributes:
Just like every object on a computer must be identifier, a web control must also follow this rule. To make it possible to identify a web control, its tag is equipped with an attribute named ID. This attribute makes it possible to refer to a control in your code. To specify this characteristic, assign it the desired name for the control. Here is an example:
<asp:Web-Control ID="ctlCommonName" runat="server"></asp:Web-Control>
When a web page is opening on a web page visitor's computer, each control must occupy some space in memory. To do that, it must be loaded in memory. As this is going on, the control fires an event named Load. You can use it to take any necessary early action before the user can take possession of the control.
When a web page comes up, the controls on it must be initialized to get ready to be displayed on the page. When this happens, each control fires an event named Init. You can use this event to take some action on the control.
After a visitor has used a web page, he or she might switch to another page or close the browser. At that time, each control on the web page must free the computer memory it was using. As this is being done, each control fires an event named Unload. Most of the times you don't need to do anything. Still, if you want, you can catch this event and do what you judge necessary.
The web controls used on a web page are implemented by classes of their names in the .NET Framework. You can use the class of a control to manipulate or manage it. Because web controls are firstly made to function on a web page, they are created as HTML tags.
Each attribute as a name and can have a value. To visually identify an attribute, on a web form, click the control. In the Properties window, click the Properties button. To specify or change the value of an attribute, click its name and type the value.
To manually access an attribute, type its name in the control's tag. To specify its value, assign it to the attribute. The formula is:
The attributes of a web control are stored in a list named Attributes. To programmatically get the list of attributes of a control, type its ID, followed by a period, followed by Attributes.
To use a control on the form, the control must be enabled. This characteristics is controlled by a Boolean attribute named Enabled. Its default value is True, which means the control can be used. If you want to disable a control by default, set this attribute to False.
To navigate among the controls on a web page, a visitor can keep pressing Tab. To help the user quickly move to a control, you can make it possible to press Alt + a key on the keyboard. To support this, the controls are equipped with an attribute named AccessKey.
To visually specify an access key, on the form, click the control. In the Properties section of the Properties window, click AccessKey and type a letter, such as A. Then, to access that control, the visitor can press Alt + A.
When you add a control to a web form, it assumes some default dimensions, especially the width. If the default width is not right, you can change it. To visually change the width in Microsoft Visual Studio or Microsoft Visual Web Developer, you can click the control, position the mouse on the right side, and drag to the right or to the left. As an alternative, click the control. In the Properties window, click Width and type the desired value.
When designing a control, you can specify its characteristics in the Properties window or using the attributes of the control's tag. An alternative is to create a style sheet that contains the desired classes.
To visually specify the desired class of a style to be applied to a control, on the form, click the control. In the Properties section of the Properties window, click CssClass and type the name of the CSS class. To manually specify the CSS class, access its CssClass attribute and assign the CSS class name to it.