Using ASP.NET Web Server Controls


In addition to providing server-enabled HTML controls, ASP.NET provides a list of controls that provide much more enhanced functionality to developer GUI-rich, Web-based applications. As discussed earlier, these controls have become the preferred way of developing Web applications instead of (and in addition to) using the basic HTML controls (see Table 8.2).

Table 8.2. ASP.NET Web Server Controls

ASP .NET WEB SERVER CONTROL

DESCRIPTION

ABBREVIATED CODE SYNTAX

AdRotator

Ad banner display

 <asp:AdRotator id="..."  AdvertisementFile="..."  KeyWordFilter="..."  Target="..."  OnAdCreated="..."  runat="server"/> 

Button

Push button

 <asp:Button id=..."  Text="..."  OnClick="..."  runat="server"/> 

Calendar

Calendar control, provides one-month calendar (with next /previous month options) display to select a particular date

 <asp:Calendar id=..."  DayNameFormat="..." SelectedDate="..."  OnSelectionChanged="..."  ...  runat="server"/> 

CheckBox

Single selection true/false check box control

 <asp:CheckBox id=..."  Text="..."  Checked="..."  OnCheckedChanged="..."  runat="server"/> 

CheckBoxList

Multiselection check box control

 <asp:CheckBoxList id=..."  RepeatLayout="..."  runat="server">  <asp:ListItem>...</asp:ListItem>  ... </asp:CheckBoxList> 

DataGrid

Tabular data bound grid

 <asp:DataGrid id=..."  ...  runat="server"/> 

DataList

Template-based data list display

 <asp:DataList id=..."  runat="server">   <HeaderStyle>...</HeaderStyle>   <AlternatingStyle/>     <HeaderTemplate>    ...    </HeaderTemplate>    <ItemTemplate>    ...    </ItemTemplate> </asp:DataList> 

DropDownList

Single-selection drop-down list

 <asp:DropDownList id=..."  runat="server">   <asp:ListItem>...</asp:ListItem>   ... </asp:DropDownList> 

HyperLink

Link to another page

 <asp:HyperLink id=..."   ImageUrl="..."   NavigateUrl="..."   runat="server">...</asp:HyperLink> 

Image

Image

 <asp:Image id=..."  ImageUrl="..."  runat="server"/> 

ImageButton

Image map

 <asp:ImageButton id=..."   OnClick="..."   ImageUrl="..."   runat="server"/> 

Label

Static text/label

 <asp:Label id=..."  runat="server">...</asp:Label> 

LinkButton

Button styled as a hyperlink

 <asp:LinkButton id=..."  OnClick="..."  runat="server"/> 

ListBox

Single/multiselection list box

 <asp:ListBox id=..."   DataSource="..."   runat="server">   <asp:ListItem>...</asp:ListItem> </asp:ListBox> 

Literal

Static text placeholder

 <asp:Literal id=..."   Text="..."   runat="server"/> 

Panel

Container for other controls, rendered as <div>

 <asp:Panel id=..."   runat="server">  ...other controls... </asp:Panel> 

PlaceHolder

Provides access to a location in a page for programmatically adding controls

 <asp:PlaceHolder id=..."  runat="server"/> 

RadioButton

Radio button

 <asp:RadioButton id=..."   Checked="..."   OnCheckedChanged="..."  runat="server"/> 

RadioButtonList

Group of radio buttons

 <asp:RadioButtonList id=..."   runat="server">   <asp:ListItem>...</asp:ListItem> </asp:RadioButtonList> 

Repeater

Data-bound list control with provision to repeat a layout template

 <asp:Repeater id=..."   DataSource   runat="server">   <HeaderTemplate/>   <ItemTemplate/> </asp:Repeater> 

Table, TableRow, TableCell

Provides programmatic table manipulation

 <asp:Table id=..."  runat="server">    <asp:TableRow>       <asp:TableCell/>    </asp:TableRow> </asp:Table> 

TextBox

Single and multiline text boxes

 <asp:TexBox id=..."   Rows="..." Text="..."   Wrap="..." OnTextChanged="..."   runat="server"/> 

Xml

XML/XSL transformation

 <asp:Xml id=..."   Document="..."   Transform="..."   runat="server"/> 

Applying Style to Controls

ASP.NET controls can be styled. What that implies is that depending on the control, a number of attributes (such as colors and fonts) are available to style it (see Figure 8.3). This is very similar to the styling of Windows Forms “based controls; even the attribute names are very similar. This goes along with the philosophy of bringing the ASP.NET and Windows Forms programming models closer together.

 
 <%@ Page Language="C#" %> <body>     <form runat="server">      <asp:Label id="message" ForeColor="Red" text="Hello" runat="server"/>     </form> </body> </html> 
Figure 8.3. Hello World with style!

In addition to the preceding style attributes (ForeColor, for example), some controls also provide the capability to specify the style of individual elements of the control. For instance, the following is a code snippet that shows a calendar control with the selected date styled as green (see Figure 8.4). This can be applied in a flight reservation example that provides styles of dates in different colors and fonts, depending on what kind of fares are available.

 
 <%@ Page Language="C#" %> <body>     <form runat="server">       <asp:Calendar id="fromDate"           runat="server">            <SelectedDayStyle ForeColor="White"                   BackColor="Black"/>         </asp:Calendar>     </form> </body> </html> 
Figure 8.4. Styled calendar control.



Microsoft.Net Kick Start
Microsoft .NET Kick Start
ISBN: 0672325748
EAN: 2147483647
Year: 2003
Pages: 195
Authors: Hitesh Seth

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net