One of the great luxuries of ASP.NET is the ability to use server controls, specialized server-side objects unique to the ASP.NET development environment which offer a method of adding elements to a web page which have enhanced functionality. To customize the way in which a given server control will function, you specify its properties, the attributes which the control possess. Some properties are unique to a given type of control. However, there are also a number of properties which are common to all server controls. This article examines these common properties.
Setting control properties is dead easy: simply right-click the control and choose Properties from the context menu. Alternatively, if the Properties window is already visible, simply highlight the control to displays its properties.
“ID” is a property which allows you to add a unique name to each element. This ties in with the “id” attribute assigned to HTML elements but is also used by server-side code as a way of referring to the element. All server controls must have an ID, so a default ID is assigned to a control as soon as it is created. Whilst it is possible to be lazy and leave these default IDs in place, it makes much more sense to give each control a descriptive name which matches its role within the context of that page. Many developers like to add further clarity to the name of a control by using a short prefix denoting its type; for example, “txt…” for TextBox controls and “lbl… ” for label controls.
Those properties which determine how the control looks are located in the “Appearance” section of the Properties window. It contains such properties as the “BackColor” and “ForeColor” as well as the sub-category “Font”. The “Font” sub-category allows you to set the font, size and style of the text within a control. The text property determines the text which is displayed on the control. With some control, like the TextBox control, the text property is normally left blank. With other controls, such as labels and buttons, the text property is essential and will need to be changed from its default value.
Use the TabIndex property in order to specify the order in which elements are activated when using the Tab key to navigate the page. To use this feature, simply assign a number to the TabIndex for each element on the page. Controls with a low TabIndex number will be accessed before those with a higher TabIndex.
If you would like to learn more about ASP.NET training courses, visit Macresource Computer Training, an independent computer training company offering ASP.NET Classes at their central London training centre.