Slide 13.9: Web server controls
Slide 13.11: Web server controls (cont.)
Home

Web Server Controls (Cont.)


The previous example declares two web server controls:
Label
It displays text on a web page. In this example, the ID of the Label is Mess and is used for displaying the result by using its property Text, which gets or sets the text content of the Label control.

CheckBoxList
It creates a multi selection check box group. The ID of the CheckBoxList is Check1. Two of its properties are set in ASP.NET:

  • Items (inherited from ListControl), which is used to created the six items, Item 1, Item 2, ..., and Item 6

  • AutoPostBack (inherited from ListControl), which gets or sets a value indicating whether a postback to the server automatically occurs when the user changes the list selection

The event SelectedIndexChanged occurs when the selection from the list control changes between posts to the server.
  <asp:CheckBoxList ID="Check1" runat="server"
    AutoPostBack="True"
    onselectedindexchanged="Check1_SelectedIndexChanged">
The subroutine Check1_SelectedIndexChanged is called when SelectedIndexChanged. The following three properties are used:

  • Count (inherited from ListItemCollection), which gets the number of ListItem objects in the collection

  • Selected (inherited from ListItem), which gets or sets a value indicating whether the item is selected

  • Text (inherited from ListItem), which gets or sets the text displayed in a list control for the item represented by the ListItem