Server Controls and Page Object Reference





Server Controls and Page Object Reference

This section provides a quick reference to the key objects described in this chapter. Space constraints prevent us from documenting every object in the .NET framework in this book. For the sake of brevity and conciseness, we include only the most important objects here. For more information on the other objects in the .NET framework, consult the .NET Framework Reference online help file.

Validation controls are covered in Chapter 11.

This chapter covers the Page framework classes in ASP.NET, including the Page object itself, its children, and user-interface controls (HTML controls and server controls). The following sections provide a brief reference to the properties, methods, and events provided by those classes.

AdRotator Class

Member of System.Web.UI.WebControls.

The AdRotator class enables you to display a graphical advertisement on your Web page, changing (or "rotating") the advertisement from a list of graphical URLs. Because they are stored in the form of URLs, the graphics and the pages they link to can reside anywhere on the Web.

Properties
AccessKey CssClass Site
AdvertisementFile Enabled Style
BackColor EnableViewState TabIndex
BorderColor Font Target
BorderStyle ForeColor TemplateSourceDirectory
BorderWidth Height ToolTip
BackColor ID UniqueID
ClientID KeywordFilter Visible
Controls NamingContainer Width
ControlStyle Page  
ControlStyleCreated Parent  
Methods
AddAttributesToRender GetHashCode OnUnload
AddParsedSubObject GetType RaiseBubbleEvent
ApplyStyle HasControls Render
ClearChildViewState IsLiteralContent RenderBeginTag
CopyBaseAttributes LoadViewState RenderChildren
CreateChildControls MapPathSecure RenderContents
CreateControlCollection MemberWiseClone RenderControl
CreateControlStyle MergeStyle RenderEndTag
DataBind OnAdCreated ResolveUrl
Dispose OnBubbleEvent SaveViewState
EnsureChildControls OnDataBinding ToString
Equals OnInit TrackViewState
Finalize OnLoad  
FindControl OnPreRender  
Events
AdCreated Init UnLoad
DataBinding Load  
Disposed PreRender  

The list of advertisements is stored in an XML file. Listing 2.28 shows an example of an XML file.

Listing 2.28 Using the AdRotator Class
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
    <Ad>
        <ImageUrl>ad-1.png</ImageUrl>
        <NavigateUrl>http://www.redblazer.com/</NavigateUrl>
        <AlternateText>Advertisement Number One</AlternateText>
    </Ad>
    <Ad>
        <ImageUrl>ad-2.png</ImageUrl>
        <NavigateUrl>http://www.redblazer.com/</NavigateUrl>
        <AlternateText>Advertisement Number Two</AlternateText>
    </Ad>
</Advertisements>

The ImageUrl node denotes which image to display. The NavigateUrl note indicates the page to which the advertisement is linked. The value of the AlternateText node is displayed if the browser has graphics turned off in the browser; it's also displayed as a pop-up tool tip for the image.

You can have as many Ad elements as you want; the AdRotator will randomly switch between them. To see this, reload the page several times. (To avoid viewing a cached version of the page, be sure you press Ctrl+F5 rather than using the View, Refresh menu command in your browser.)

NOTE

The standard dimensions for a Web advertising banner is 468 pixels wide by 60 pixels high. You can, of course, use the AdRotator control to display images of any dimensions you want.


You link an XML file with an instance of an AdRotator control by assigning the name of the file to the AdRotator control's AdvertisementFile property. Listing 2.29 shows an example.

Listing 2.29 Using an AdRotator Control to Display Various Advertising Banners in an ASP.NET Page
<%@ Page Language="c#" debug="False" %>
<HTML>
  <HEAD>
    <title>ASP.NET AdRotator Control</title>
  </HEAD>
  <body>
    <form runat="server">
      <asp:AdRotator id="AdRotator1" runat="server" Width="468px" Height="60px"
AdvertisementFile="ads.xml" />
    </form>  </body>
</HTML>

As you can see, no event procedure code is necessary to use the AdRotator control (although the control does provide an AdCreated event you can use to intercept and reassign the properties of the advertisement before it is rendered on the page).

Button Class

Member of System.Web.UI.WebControls.

The Button class is the ASP.NET Web control equivalent of the HTML submit and button elements. The class abstracts both elements, adding a number of additional properties and events as well.

Properties
AccessKey ControlStyle Page
Attributes ControlStyleCreated Parent
BackColor EnableViewState Site
BorderColor CssClass Style
BorderStyle Enabled TabIndex
BorderWidth EnableViewState TemplateSourceDirectory
CausesValidation Font Text
ClientID ForeColor ToolTip
CommandArgument Height UniqueID
CommandName ID Visible
Controls NamingContainer Width
Methods
AddAttributesToRender GetHashCode OnPreRender
AddParsedSubObject GetType OnUnload
ApplyStyle HasControls RaiseBubbleEvent
ClearChildViewState IsLiteralContent Render
CopyBaseAttributes LoadViewState RenderBeginTag
CreateChildControls MapPathSecure RenderContents
CreateControlCollection MemberwiseClone RenderControl
CreateControlStyle MergeStyle RenderEndTag
DataBind OnBubbleEvent ResolveUrl
Dispose OnClick SaveViewState
EnsureChildControls OnCommand ToString
Equals OnDataBinding TrackViewState
Finalize OnInit  
FindControl OnLoad  
Events
Click Disposed PreRender
Command Init UnLoad
DataBinding Load  

Code examples that use the Button object are given throughout this book. Essentially, only two members of the Button object are used with any regularity: the Text property, to display text on the button face, and the Click event, which generates a form submit.

Calendar Class

Member of System.Web.UI.WebControls.

The Calendar class renders a calendar in HTML. In most cases, you'll want to respondto a user selecting a date in the calendar; do this by handling the control's SelectionChanged event.

Properties
AccessKey Font ShowGridLines
Attributes ForeColor ShowNextPrevMonth
BackColor HasChildViewState ShowTitle
BorderColor Height Site
BorderStyle ID Style
BorderWidth IsTrackingViewState TabIndex
CellPadding NamingContainer TagKey
CellSpacing NextMonthText TagName
ChildControlsCreated NextPrevFormat TemplateSourceDirectory
ClientID NextPrevStyle TitleFormat
Context OtherMonthDayStyle TitleStyle
Controls Page TodayDayStyle
ControlStyle Parent TodaysDate
ControlStyleCreated PrevMonthText ToolTip
CssClass SelectedDate UniqueID
DayHeaderStyle SelectedDates ViewState
DayNameFormat SelectedDayStyle ViewStateIgnoresCase
DayStyle SelectionMode Visible
Enabled SelectMonthText VisibleDate
EnableViewState SelectorStyle WeekendDayStyle
Events SelectWeekText Width
FirstDayOfWeek ShowDayHeader  
Methods
AddAttributesToRender FindControl OnSelectionChanged
AddParsedSubObject GetHashCode OnUnload
ApplyStyle GetType OnVisibleMonthChanged
BuildProfileTree HasControls RaiseBubbleEvent
ClearChildViewState IsLiteralContent Render
CopyBaseAttributes LoadViewState RenderBeginTag
CreateChildControls MapPathSecure RenderChildren
CreateControlCollection MemberwiseClone RenderContents
CreateControlStyle MergeStyle RenderControl
DataBind OnBubbleEvent RenderEndTag
Dispose OnDataBinding ResolveUrl
EnsureChildControls OnDayRender SaveViewState
Equals OnInit  
Finalize OnLoad ToString
  OnPreRender TrackViewState
Events
DataBinding Init SelectionChanged
DayRender Load Unload
Disposed PreRender VisibleMonthChanged

Listing 2.30 shows an example of a page that displays a Calendar control and a label. When the user selects a date in the calendar, the label indicates which date the user selected.

Responding to a User Selection in the Calendar Server Control
<%@ Page Language="c#" debug="false"%>
<SCRIPT runat='server'>
  void Calendar1_SelectionChanged(System.Object sender, System.EventArgs e)
  {
    Label1.Text = "The date you selected is " + Calendar1.SelectedDate;
  }
</SCRIPT>
<HTML>
  <HEAD>
    <TITLE>ASP.NET Calendar Control</TITLE>
  </HEAD>
  <body>
    <form method="post" runat="server">
      <asp:Calendar id="Calendar1" OnSelectionChanged="Calendar1_SelectionChanged"
runat="server"></asp:Calendar>
      <BR>
      <asp:Label id="Label1" runat="server"></asp:Label>
    </form>
  </body>
</HTML>

CheckBox Class

Member of System.Web.UI.WebControls.

The CheckBox class is the Web control abstraction of the HTML CHECKBOX element, used to enable the user to select a true/false or yes/no condition.

Properties
AccessKey CssClass Style
Attributes Enabled TabIndex
AutoPostBack EnableViewState TagKey
BackColor Events TagName
BorderColor Font TemplateSourceDirectory
BorderStyle ForeColor Text
BorderWidth HasChildViewState TextAlign
Checked Height ToolTip
ChildControlsCreated ID UniqueID
ClientID IsTrackingViewState ViewState
Context NamingContainer ViewStateIgnoresCase
Controls Page Visible
ControlStyle Parent Width
ControlStyleCreated Site  
Methods
AddAttributesToRender GetHashCode OnUnload
AddParsedSubObject GetType RaiseBubbleEvent
ApplyStyles HasControls Render
ClearChildViewState IsLiteralContent RenderBeginTag
CopyBaseAttributes LoadViewState RenderChildren
CreateChildControls MapPathSecure RenderContents
CreateChildCollection MemberwiseClone RenderControl
CreateControlStyle MergeStyle RenderEndTag
DataBind OnBubbleEvent ResolveUrl
Dispose OnCheckedChanged SaveViewState
Equals OnDataBinding ToString
EnsureChildControls OnInit TrackViewState
Finalize OnLoad  
FindControl OnPreRender  
Events
CheckedChanged Init Unload
DataBinding Load  
Disposed PreRender  

You can determine whether the check box is checked by inspecting its Boolean Checked property. Setting its Text property assigns a text label to the check box; the TextAlign property determines where the accompanying text label is displayed. Listing 2.31 shows an example.

Listing 2.31 Reading the Checked Value of an ASP.NET CheckBox Server Control
<%@ Page Language="c#" debug="False" %>
<HTML>
  <HEAD>
    <title>ASP.NET CheckBox Control</title>
    <SCRIPT runat='server'>
      void CheckChanged(Object Sender, EventArgs e)
      {
        if(CheckBox1.Checked)
        CheckBox1.Text = "Thank you for checking this.";
        else
        CheckBox1.Text = "Check This!";
      }
    </SCRIPT>
  </HEAD>
  <body>
    <form runat="server">
      <asp:CheckBox id="CheckBox1" runat="server" Text="Check This!"
TextAlign="Left" /><BR>
      <asp:button OnClick="CheckChanged" text="Send" runat="server" ID="Button1" />
    </form>
  </body>
</HTML>

Control Class

Member of System.Web.UI.

The Control class serves as the base class for all ASP.NET server controls.

Properties
ChildControlsCreated HasChildViewState Site
ClientID ID TemplateSourceDirectory
Context IsTrackingViewState UniqueID
Controls NamingContainer ViewState
EnableViewState Page ViewStateIgnoresCase
Events Parent Visible
Methods
AddParsedSubObject GetHashCode OnUnload
BuildProfileTree GetType OnUnload
ClearChildViewState HasControls RaiseBubbleEvent
CreateChildControls IsLiteralContent Render
CreateControlCollection LoadViewState RenderChildren
DataBind MemberwiseClone RenderControl
Dispose OnBubbleEvent ResolveUrl
EnsureChildControls OnDataBinding SaveViewState
Equals OnInit  
Finalize OnLoad ToString
FindControl OnPreRender TrackViewState
  OnPreRender  
Events
DataBinding Init PreRender
Disposed Load Unload

DataGrid Class

Member of System.Web.UI.WebControls.

The DataGrid class enables you to display data in a tabular (row and column) format. Like all data-bound ASP.NET controls, the DataGrid need not be bound to a traditional relational data source; you can also bind to an array or one of the many collection objects provided in the .NET framework.

The HTML output of this control is a table, but the DataGrid class adds a number of useful additional accoutrements such as data paging and formatting.

Properties
AccessKey CurrentPageIndex PageCount
AllowCustomPaging DataKeys PagerStyle
AllowPaging DataMember PageSize
AllowSorting DataSource Parent
AlernatingItemStyle EditItemIndex SelectedIndex
Attributes EditItemStyle SelectedItem
AutoGeneratteColumns Enabled SelectedItemStyle
BackColor EnableViewState ShowFooter
BackImageUrl Events ShowHeader
BorderColor Font Site
BorderStyle FooterStyle Style
BorderWidth ForeColor TabIndex
CellPadding GridLines TagKey
CellSpacing HasChildViewState TagName
ChildControlsCreated HeaderStyle TemplateSourceDirectory
  Height  
ClientID HorizontalAlign ToolTip
Columns ID UniqueID
Context IsTrackingViewState ViewState
Controls Items ViewStateIgnoresCase
ControlStyle ItemStyle VirtualItemCount
ControlStyleCreated NamingContainer Visible
CssClass Page Width
Methods
AddAttributesToRender HasControls OnPageIndexChanged
AddParsedSubObject IsLiteralContent OnPreRender
ApplyStyle LoadViewState OnSelectedIndexChanged
ClearChildViewState MapPathSecure OnSortCommand
CopyBaseAttributes MemberwiseClone OnUnload
CreateChildControls MergeStyle OnUpdateCommand
CreateControlCollection OnBubbleEvent Render
CreateControlStyle OnCancelCommand RenderBeginTag
DataBind OnDataBinding RenderChildren
Dispose OnDeleteCommand RenderContents
Equals OnEditCommand RenderControl
EnsureChildControls OnInit RenderEndTag
Finalize OnItemCommand ResolveUrl
FindControl OnItemCreated SaveViewState
GetHashCode OnItemDataBound ToString
GetType OnLoad TrackViewState
Events
CancelCommand ItemCommand SelectedIndexChanged
DataBinding ItemCreated SortCommand
DeleteCommand ItemDataBound Unload
Disposed Load UpdateCommand
EditCommand PageIndexChanged  
Init PreRender  

You can find a number of code examples that utilize the DataGrid control in Chapter 11.

DataList Class

Member of System.Web.UI.WebControls.

The DataList class enables you to display data in a list. The control is similar to the DataGrid control, but instead of displaying multiple categories of data in a tabular (row-and-column) format, the DataList displays a single list of data in a single row. This row can wrap into multiple columns, however.

The various elements of the DataList (header, footer, and items) are divided up into sections and formatted according to templates. Templates are XML sections embedded in the script declaration of the control.

Properties
AccessKey EditItemTemplate RepeatColumns
AlternatingItemStyle Enabled RepeatDirection
AlternatingItemTemplate EnableViewState RepeatLayout
Attributes ExtractTemplateRows SelectedIndex
BackColor Events SelectedItemStyle
BorderColor Font SelectedItemTemplate
BorderStyle FooterStyle SeparatorStyle
BorderWidth FooterTemplate SeparatorTemplate
CellPadding ForeColor ShowFooter
CellSpacing GridLines ShowHeader
ChildControlsCreated HasChildViewState Site
ClientID HeaderStyle Style
Context HeaderTemplate TabIndex
Controls Height TagKey
ControlStyle HorizontalAlign TagName
ControlStyleCreated ID TemplateSourceDirectory
CssClass IsTrackingViewState ToolTip
DataKeyField Items UniqueID
DataKeys ItemStyle ViewState
DataMember ItemTemplate ViewStateIgnoresCase
DataSource NamingContainer Visible
EditItemIndex Page Width
EditItemStyle Parent  
Methods
AddAttributesToRender HasControls OnPreRender
AddParsedSubObject IsLiteralContent OnSelectedIndexChanged
ApplyStyle LoadViewState OnUnload
ClearChildViewState MapPathSecure OnUpdateCommand
CopyBaseAttributes MemberwiseClone RaiseBubbleEvent
CreateChildControls MergeStyle Render
CreateControlCollection OnBubbleEvent RenderBeginTag
CreateControlStyle OnCancelCommand RenderChildren
DataBind OnDataBinding RenderContents
Dispose OnDeleteCommand RenderControl
Equals OnEditCommand RenderEndTag
EnsureChildControls OnInit ResolveUrl
Finalize OnItemCommand SaveViewState
FindControl OnItemCreated ToString
GetHashCode OnItemDataBound TrackViewState
GetType OnLoad  
Events
CancelCommand Init PreRender
DataBinding ItemCommand SelectedIndexChanged
DeleteCommand ItemCreated Unload
Disposed ItemDataBound UpdateCommand
EditCommand Load  

Listing 2.32 provides an example of a DataList control bound to a Hashtable object.

Listing 2.32 Displaying Data in a Hashtable Object in a DataList Server Control
<% @Page language="C#" debug="true" %>
<html>
  <head>
    <title>ASP.NET DataList Control</title>
    <script runat="server">

    void Page_Load(Object Sender, EventArgs e)
    {
      if(!IsPostBack)
      {
        Hashtable h  = new Hashtable();
        h.Add ("SF", "San Francisco");
        h.Add ("AZ", "Arizona");
        h.Add ("CO", "Colorado");
        h.Add ("SD", "San Diego");
        h.Add ("LA", "Los Angeles");

        DataList1.DataSource = h;
        DataList1.DataBind();
      }
    }

    </script>
  </head>
  <body>
    <form runat="server">
      <asp:DataList id="DataList1" runat="server" BorderColor="black"
BorderWidth="1" CellPadding="3" Font-Name="Verdana" Font-Size="8pt">
        <HeaderStyle BackColor="#000000" ForeColor="#FFFF99"></HeaderStyle>
        <AlternatingItemStyle BackColor="#FFFF99"></AlternatingItemStyle>
        <HeaderTemplate>
          National League West
        </HeaderTemplate>
        <ItemTemplate>
          <%# DataBinder.Eval(Container.DataItem, "Value") %>
          [<%# DataBinder.Eval(Container.DataItem, "Key") %>]
        </ItemTemplate>
      </asp:DataList>
    </form>
  </body>
</html>

Note that, as with all data-bindable objects, you can bind the DataList to a wide variety of objects. We used the Hashtable object in this example for simplicity, but you could bind to an ArrayList, a DataSet, or any other list type.

DropDownList Class

Member of System.Web.UI.WebControls.

The DropDownList class is the server control abstraction of the HTML SELECT. Like most list controls, it can be bound to data.

Properties
AccessKey DataMember SelectedIndex
Attributes DataSource SelectedItem
AutoPostBack DataTextField Site
BackColor DataTextFormatString Style
BorderColor DataValueField TabIndex
BorderStyle Enabled TagKey
BorderWidth EnabledViewState TagName
ChildControlsCreated Font TemplateSourceDirectory
ClientID ForeColor ToolTip
Context IsTrackingViewState UniqueID
Controls Items ViewState
ControlStyle NamingContainer ViewStateIgnoresCase
ControlStyleCreated Page Visible
CssClass Parent Width
Methods
AddAttributesToRender GetType Render
AddParsedSubObject HasControls RenderBeginTag
ApplyStyle IsLiteralContent RenderChildren
ClearChildViewState LoadViewState RenderContents
CopyBaseAttributes MapPathSecure RenderControl
CreateChildControls MemberwiseClone RenderEndTag
CreateControlCollection MergeStyle ResolveUrl
CreateControlStyle OnBubbleEvent SaveViewState
DataBind OnDataBinding ToString
Dispose OnInit TrackViewState
Equals OnLoad  
EnsureChildControls OnPreRender  
Finalize OnSelectedIndexChanged  
FindControl OnUnload  
GetHashCode RaiseBubbleEvent  
Events
Init PreRender DataBinding
SelectedIndexChanged Unload Disposed Load

Listing 2.33 shows an example of a DropDownList object that is bound to an ArrayList object.

Listing 2.33 Binding a DropDownList Control to Data Contained in an ArrayList Object
<% @Page language="C#" debug="true" %>
<html>
  <head>
   <title>ASP.NET DropDownList Control</title>
   <script runat="server">

    void Page_Load(Object Sender, EventArgs e)
    {
      if(!IsPostBack)
      {
        ArrayList list = new ArrayList();
        list.Add ("San Francisco");
        list.Add ("Arizona");
        list.Add ("Colorado");
        list.Add ("San Diego");
        list.Add ("Los Angeles");

        DropDownList1.DataSource = list;
        DropDownList1.DataBind();
      }
    }

    void Pick_Click(Object Sender, EventArgs e)
    {
      Label1.Text = "You selected " + DropDownList1.SelectedItem.Text;
    }

  </script>
  </head>
  <body>
    <form runat="server">
      <asp:DropDownList id="DropDownList1" runat="server" BorderColor="black"
BorderWidth="1" Font-Name="Verdana" Font-Size="8pt"></asp:DropDownList>
      <asp:button text="Pick" OnClick="Pick_Click" runat="server" ID="Button1"
/><BR>
      <asp:label id="Label1" runat="server" />
    </form>
  </body>
</html>

Use the SelectedItem object contained by the DropDownList control to return information about the item selected by the user. The SelectedItem object (an instance of System.Web.UI.WebControls.ListItem) contains a Text property as well as a Value property, enabling you to retrieve both the displayed value and the key associated with the selected value.

In addition to binding the DropDownList object to a list object such as ArrayList, you can also hard-code the list definitions by using <asp:listitem> subelements in the DropDownList definition.

HttpApplication Class

Member of System.Web. This object is typically accessed as the Application object contained in the ASP.NET Page object.

The HttpApplication class provides a way to store information that has application scope. The Application object contains instance objects such as Request and Response objects (instances of the HttpRequest and HttpResponse classes, respectively) that you can use to access the contents of conventional HTML forms.

Properties
Application Request Site
Context Response User
Events Server  
Modules Session  
Methods
AddOnAcquireRequestStateAsync AddOnReleaseRequestStateAsync GetHashCode
AddOnAuthenticateRequestAsync AddOnResolveRequestCacheAsync GetType
AddOnAuthorizeRequestAsync AddOnUpdateRequestCacheAsync GetVaryByCustomString
AddOnBeginRequestAsync CompleteRequest Init
AddOnEndRequestAsync Dispose MemberwiseClone
AddOnPostRequestHandlerExecuteAsync Equals ToString
AddOnPreRequestHandlerExecuteAsync Finalize  

HttpRequest Class

Member of System.Web.UI.

The HttpRequest class represents a request made by a client. It is typically accessed by programmers through the Request object contained in the ASP.NET Page object.

You can use the Request object to retrieve the value of cookies, read HTTP header information generated by a Web request, get information about the browser that made the request, and poll the client for security-related information.

Properties
AcceptTypes Files PhysicalApplicationPath
ApplicationPath Filter PhysicalPath
Browser Form QueryString
ClientCertificate Headers RawUrl
ContentEncoding HttpMethod UrlReferrer
ContentLength InputStream UserAgent
ContentType IsAuthenticated UserHostAddress
Cookies IsSecureConnection UserHostName
CurrentExecutionFilePath Params UserLanguages
FilePath PathInfo  
Methods
BinaryRead GetType SaveAs
Equals MapImageCoordinates ToString
Finalize MapPath  
GetHashCode MemberwiseClone  

HttpResponse Class

Member of System.Web.UI.

The HttpResponse class represents the data sent to a client in reply to a request. This can include the response itself (handled by the Write method) as well as headers and other configuration data (such as page cache expiry and HTTP headers).

Properties
Buffer ContentType Output
BufferOutput Cookies OutputStream
Cache Expires Status
CacheControl ExpiresAbsolute StatusCode
Charset Filter StatusDescription
ContentEncoding IsClientConnected SuppressContent
Methods
AddCacheItemDependencies Clear GetType
AddCacheItemDependency ClearContent MemberwiseClone
AddFileDependencies ClearHeaders Pics
AddFileDependency Close Redirect
AddHeader End RemoveOutputCacheItem
AppendHeader Equals ToString
AppendToLog Finalize Write
ApplyAppPathModifier Flush WriteFile
BinaryWrite GetHashCode  

HttpServerUtility Class

Member of System.Web.UI.

The HttpServerUtility class provides a variety of utilities for ASP.NET programmers, such as mapping a file request to the file system of the Web server (the MapPath method) and encoding data for use in a URL (the UrlEncode method). It is typically accessed by ASP.NET developers as the Server object contained by the ASP.NET Page object.

Properties
MachineName ScriptTimeout  
Methods
ClearError GetHashCode MemberwiseClone
CreateObject GetLastError ToString
CreateObjectFromClsid GetType Transfer
Equals HtmlDecode UrlDecode
Execute HtmlEncode UrlEncode
Finalize MapPath UrlPathEncode

HttpSessionState Class

Member of System.Web.UI.

The HttpSessionState class is used to store and retrieve Session state in an ASP.NET application. It is typically accessed by ASP.NET developers in the form of the Session object, contained by the ASP.NET Page object.

Properties
CodePage IsReadOnly Mode
Contents IsSyncronized SessionID
Count Item StaticObjects
IsCookieless Keys SyncRoot
IsNewSession LCID Timeout
Methods
Abandon Finalize Remove
Add GetEnumerator RemoveAll
Clear GetHashCode RemoveAt
CopyTo GetType ToString
Equals MemberwiseClone  

Hyperlink Class

Member of System.Web.UI.WebControls.

The Hyperlink class is the ASP.NET server control abstraction of the HTML A element.

Properties
AccessKey EnabledViewState Style
Attributes Events TabIndex
BackColor Font TagKey
BorderColor ForeColor TagName
BorderStyle HasChildViewState Target
BorderWidth Height TemplateSourceDirectory
ChildControlsCreated ID Text
ClientID ImageUrl ToolTip
Context IsTrackingViewState UniqueID
Controls NamingContainer ViewState
ControlStyle NavigateUrl ViewStateIgnoresCase
ControlStyleCreated Page Visible
CssClass Parent Width
Enabled Site  
Methods
AddAttributesToRender GetHashCode OnPreRender
AddParsedSubObject GetType OnUnload
ApplyStyle HasControls RaiseBubbleEvent
ClearChildViewState IsLiteralContent Render
CopyBaseAttributes LoadViewState RenderBeginTag
CreateChildControls MapPathSecure RenderChildren
CreateControlCollection MemberwiseClone RenderContents
CreateControlStyle MergeStyle RenderControl
DataBind OnBubbleEvent RenderEndTag
Dispose OnDataBinding ResolveUrl
EnsureChildControls OnInit SaveViewState
Equal OnLoad ToString
Finalize OnPreRender TrackViewState
FindControl OnUnload  

Use the Text property of the Hyperlink control to specify the text the control should display. Use the NavigateUrl property to determine which page to navigate to. As with the HTML target attribute, you can specify the target window to navigate to by assigning a value to the control's Target property; special values such as "_self" and "_new" are recognized by the control.

Image Class

Member of System.Web.UI.WebControls.

The Image class is the ASP.NET server control abstraction of the HTML IMG element.

Properties
AccessKey EnsureChildControls Page
AddAttributesToRender Events Parent
AddParsedSubObject Finalize RaiseBubbleEvent
AlternateText Font Render
Attributes ForeColor RenderChildren
BackColor HasChildViewState RenderContents
BorderColor Height SaveViewState
BorderStyle ID Site
Borderwidth ImageAlign Style
ChildControlsCreated ImageUrl TabIndex
ClearChildViewState IsLiteralContent TagKey
ClientID IsTrackingViewState TagName
Context LoadViewState TemplateSourceDirectory
Controls MapPathSecure ToolTip
ControlStyle MemberwiseClone TrackViewState
ControlStyleCreated NamingContainer UniqueID
CreateChildControls OnBubbleEvent ViewState
CreateControlCollection OnDataBinding ViewStateIgnoresCase
CreateControlStyle OnInit Visible
CssClass OnLoad Width
Enabled OnPreRender  
EnableViewState OnUnload  
Methods
ApplyStyle FindControl RenderBeginTag
CopyBaseAttributes GetHashCode RenderControl
DataBind GetType RenderEndTag
Dispose HasControls ResolveUrl
Equals MergeStyle ToString
Events
DataBinding Init PreRender
Disposed Load Unload

Use the ImageUrl property to specify which image to display. To create an image that works like a button, use the ImageButton control instead.

ImageButton Class

Member of System.Web.UI.WebControls.

The ImageButton class is another ASP.NET server control abstraction of the HTML INPUT type="image" element.

Properties
AccessKey ControlStyleCreated Parent
AlternateText CssClass Site
Attributes Enabled Style
BackColor EnableViewState TabIndex
BorderColor Events TagKey
BorderStyle Font TagName
BorderWidth ForeColor TemplateSourceDirectory
CausesValidation HasChildViewState ToolTip
ChildControlsCreated Height UniqueID
ClientID ID ViewState
CommandArgument ImageAlign ViewStateIgnoresCase
CommandName ImageUrl Visible
Context IsTrackingViewState Width
Controls NamingContainer  
ControlStyle Page  
Methods
AddAttributesToRender GetHashCode OnPreRender
AddParsedSubObject GetType OnUnload
ApplyStyle HasControls RaiseBubbleEvent
CopyBaseAttributes IsLiteralConent Render
ClearChildViewState LoadViewState RenderBeginTag
CreateChildControls MapPathSecure RenderChildren
CreateControlCollection MemberwiseClone RenderContents
CreateControlStyle MergeStyle RenderControl
DataBind OnBubbleEvent RenderEndTag
Dispose OnClick ResolveUrl
Equals OnCommand SaveViewState
EnsureChildControls OnDataBinding ToString
Finalize OnInit TrackViewState
FindControl OnLoad  
Events
Click Disposed PreRender
Command Init Unload
DataBinding Load  

Assign a value to the ImageUrl property to specify which graphic to display (just as you would with the Image control). To execute code in response to a user clicking the image, use the control's Click event, the same as you would for a Button control.

Label Class

Member of System.Web.UI.WebControls.

The Label class provides a way to programmatically create a read-only text region on the page. This region is typically rendered in HTML as a SPAN tag.

Properties
AccessKey Enabled Style
Attributes EnableViewState TabIndex
BackColor Events TagKey
BorderColor Font TagName
BorderStyle ForeColor Text
BorderWidth HasChildViewState TemplateSourceDirectory
ChildControlsCreated Height ToolTip
ClientID ID UniqueID
Context IsTrackingViewState ViewState
Controls NamingContainer ViewStateIgnoresCase
ControlStyle Page Visible
ControlStyleCreated Parent Width
CssClass Site  
Methods
AddAttributesToRender FindControl OnUnload
AddParsedSubObject Finalize RaiseBubbleEvent
ApplyStyle GetHashCode Render
ClearChildViewState GetType RenderBeginTag
CopyBaseAttributes HasControls RenderChildren
ClearChildViewState IsLiteralContent RenderContents
CreateChildControls MapPathSecure RenderControl
CreateControlCollection MemberwiseClone RenderEndTag
CreateControlStyle MergeStyle ResolveUrl
DataBind OnDataBinding SaveViewState
Dispose OnInit ToString
Equals OnLoad TrackViewState
EnsureChildControls OnPreRender  

A number of code examples involving the Label class are provided throughout this book. In nearly every case, the only member you'll typically need to access is the control's Text property.

LinkButton Class

Member of System.Web.UI.WebControls.

The LinkButton class merges the functionality of a hyperlink with the functionality of the Button control.

Properties
AccessKey ControlStyleCreated Site
Attributes CssClass Style
BackColor Enabled TabIndex
BorderColor EnableViewState TagKey
BorderStyle Events TagName
BorderWidth Font TemplateSourceDirectory
CausesValidation ForeColor Text
ChildControlsCreated HasChildViewState ToolTip
ClientID Height UniqueID
CommandArgument ID ViewState
CommandName IsTrackingViewState ViewStateIgnoresCase
Context NamingContainer Visible
Controls Page Width
ControlStyle Parent  
Methods
AddAttributesToRender Finalize OnLoad
AddParsedSubObject GetHashCode OnPreRender
ApplyStyle GetType OnUnload
ClearChildViewState HasControls RaiseBubbleEvent
CopyBaseAttributes IsLiteralContent Render
ClearChildViewState LoadViewState RenderBeginTag
CreateChildControls MapPathSecure RenderChildren
CreateControlCollection MemberwiseClone RenderContents
CreateControlStyle MergeStyle RenderControl
DataBind OnBubbleEvent RenderEndTag
Dispose OnClick ResolveUrl
Equals OnCommand SaveViewState
EnsureChildControls OnDataBinding ToString
FindControl OnInit TrackViewState
Events
Click Disposed PreRender
Command Init Unload
DataBinding Load  

Handle the control's Click event to execute code when the user clicks the control. To navigate to another Web page, use the Hyperlink control instead.

ListBox Class

Member of System.Web.UI.WebControls.

The ListBox class represents the ASP.NET server control abstraction of the HTML SELECT element.

Properties
AccessKey DataTextField SelectedIndex
Attributes DataTextFormatString SelectedItem
AutoPostBack DataValueField SelectionMode
BackColor Enabled Site
BorderColor EnableViewState Style
BorderStyle Events TabIndex
BorderWidth Font TagKey
ChildControlsCreated ForeColor TagName
ClientID HasChildViewState TemplateSourceDirectory
Context Height Text
Controls ID ToolTip
ControlStyle IsTrackingViewState UniqueID
  Items  
ControlStyleCreated NamingContainer ViewState
CssClass Page ViewStateIgnoresCase
DataMember Parent Visible
DataSource Rows Width
Methods
AddAttributesToRender Finalize OnSelectedIndexChanged
AddParsedSubObject GetHashCode OnUnload
ApplyStyle GetType RaiseBubbleEvent
ClearChildViewState HasControls Render
CopyBaseAttributes IsLiteralContent RenderBeginTag
ClearChildViewState LoadViewState RenderChildren
CreateChildControls MapPathSecure RenderContents
CreateControlCollection MemberwiseClone RenderControl
CreateControlStyle MergeStyle RenderEndTag
DataBind OnBubbleEvent ResolveUrl
Dispose OnDataBinding SaveViewState
Equals OnInit ToString
EnsureChildControls OnLoad TrackViewState
FindControl OnPreRender  

Page Class

The Page class represents a page request. All controls on a page, as well as utility objects such as Request, Response, Server, and Application (familiar to ASP.old developers), are members of the Page object in ASP.NET.

The page class is the base class from which all ASP.NET pages derive. If you create a code-behind class, it must inherit from this object.

Properties
Application Cache ClientID
ClientTarget Controls EnableViewState
ErrorPage ID IsPostBack
IsValid NamingContainer Page
Parent Request Response
Server Session Site
SmartNavigation TemplateSourceDirectory Trace
UniqueID User Validators
Visible    
Methods
DataBind DesignerInitialize Dispose
Equals FindControl GetHashCode
GetPostBackClientEvent GetPostBackClientHyperlink GetPostBackEventReference
GetType GetTypeHashCode HasControls
  IsClientScriptBlockRegistered IsStartupScriptRegistered
LoadControl LoadTemplate MapPath
ParseControl RegisterArrayDeclaration RegisterClientScriptBlock
RegisterHiddenField RegisterOnSubmitStatement RegisterRequiresPostBack
RegisterRequiresRaiseEvent RegisterStartupScript RegisterViewStateHandler
RenderControl ResolveUrl VerifyRenderingInServerForm
ToString Validate  
Events
AbortTransaction CommitTransaction DataBinding
Disposed Error Init
Load PreRender Unload

It's common for ASP.NET pages to handle the Load event of the Page object as a way to perform initialization when the page loads.

Panel Class

Member of System.Web.UI.WebControls.

The Panel class enables developers to group Web form controls. You may do this for cosmetic purposes (for example, to group the controls on a complicated form into subcategories) or to manipulate controls on a form as a unit.

Properties
AccessKey Enabled Style
Attributes EnableViewState TabIndex
BackColor Events TagKey
BackImageUrl Font TagName
BorderColor ForeColor TemplateSourceDirectory
BorderStyle HasChildViewState ToolTip
BorderWidth Height UniqueID
ChildControlsCreated HorizontalAlign ViewState
ClientID ID ViewStateIgnoresCase
Context IsTrackingViewState Visible
Controls NamingContainer Width
ControlStyle Page Wrap
ControlStyleCreated Parent  
CssClass Site  
Methods
AddAttributesToRender Finalize OnSelectedIndexChanged
AddParsedSubObject GetHashCode OnUnload
ApplyStyle GetType RaiseBubbleEvent
ClearChildViewState HasControls Render
CopyBaseAttributes IsLiteralContent RenderBeginTag
ClearChildViewState LoadViewState RenderChildren
CreateChildControls MapPathSecure RenderContents
CreateControlCollection MemberwiseClone RenderControl
CreateControlStyle MergeStyle RenderEndTag
DataBind OnBubbleEvent ResolveUrl
Dispose OnDataBinding SaveViewState
Equals OnInit ToString
EnsureChildControls OnLoad TrackViewState
FindControl OnPreRender  

RadioButton Class

Member of System.Web.UI.WebControls.

The RadioButton class represents the ASP.NET server control abstraction of the INPUT type radio. Radio buttons are grouped together; only one button in a group may be selected at a time.

Properties
AccessKey Enabled Style
Attributes EnableViewState TabIndex
AutoPostBack Events TagKey
BackColor Font TagName
BorderColor ForeColor TemplateSourceDirectory
BorderStyle GroupName Text
BorderWidth   TextAlign
Checked HasChildViewState ToolTip
ChildControlsCreated Height UniqueID
ClientID ID ViewState
Context IsTrackingViewState ViewStateIgnoresCase
Controls NamingContainer Visible
ControlStyle Page Width
ControlStyleCreated Parent  
CssClass Site  
Methods
AddAttributesToRender Finalize OnPreRender
AddParsedSubObject GetHashCode OnUnload
ApplyStyle GetType RaiseBubbleEvent
ClearChildViewState HasControls Render
CopyBaseAttributes IsLiteralContent RenderBeginTag
ClearChildViewState LoadViewState RenderChildren
CreateChildControls MapPathSecure RenderContents
CreateControlCollection MemberwiseClone RenderControl
CreateControlStyle MergeStyle RenderEndTag
DataBind OnBubbleEvent ResolveUrl
Dispose OnCheckedChanged SaveViewState
Equals OnDataBinding ToString
EnsureChildControls OnInit TrackViewState
FindControl OnLoad  

Repeater Class

Member of System.Web.UI.WebControls.

You can use the Repeater control to display bound data in a totally customized way. You do this by creating HTML templates (in a manner similar to the DataList control described earlier in this section).

Properties
AlternatingItemTemplate FooterTemplate Parent
ChildControlsCreated HasChildViewState SeparatorTemplate
ClientID HeaderTemplate Site
Context ID TemplateSourceDirectory
Controls IsTrackingViewState UniqueID
DataMember Items ViewState
DataSource ItemTemplate ViewStategnoresCase
EnableViewState NamingContainer Visible
Events Page  
Methods
  FindControl OnItemCreated
AddParsedSubObject Finalize OnItemDataBound
  GetHashCode OnLoad
  GetType OnPreRender
  HasControls OnUnload
ClearChildViewState IsLiteralContent RaiseBubbleEvent
  LoadViewState Render
  MapPathSecure RenderChildren
CreateChildControls MemberwiseClone RenderControl
CreateControlCollection   ResolveUrl
DataBind OnBubbleEvent SaveViewState
Dispose OnDataBinding ToString
Equals OnInit TrackViewState
EnsureChildControls OnItemCommand  

Listing 2.34 shows an example of a Repeater control used to display the contents of the ever-popular Hashtable object. Although you could have used another list control such as the DataGrid or DataList to perform the same work, you can see from the code that the Repeater gives you the capability to embed HTML formatting to have more granular control over the formatting of each row.

Listing 2.34 Using the Repeater Control to Build Customized Output of a Hashtable
<%@ Page Language="C#" debug="true" %>
<html>
  <head>
   <script runat="server">

    void Page_Load(Object Sender, EventArgs e)
    {
      if(!IsPostBack)
      {
        Hashtable h  = new Hashtable();
        h.Add ("SF", "San Francisco");
        h.Add ("AZ", "Arizona");
        h.Add ("CO", "Colorado");
        h.Add ("SD", "San Diego");
        h.Add ("LA", "Los Angeles");

        Repeater1.DataSource = h;
        Repeater1.DataBind();
      }
    }

  </script>
  </head>
  <body>
    <form runat="server">
      <asp:Repeater id="Repeater1" runat="server">
        <HeaderTemplate>
          <table border="0" cellpadding="5" cellspacing="1" bgcolor="#000000">
            <tr>
              <td bgcolor="#FFFF99"><b>Team</b></td>
              <td bgcolor="#FFFF99"><b>Abbreviation</b></td>
            </tr>
        </HeaderTemplate>
        <ItemTemplate>
          <tr>
            <td bgcolor="#FFFFFF">
              <%# DataBinder.Eval(Container.DataItem, "Value") %>
            </td>
            <td bgcolor="#FFFFFF">
              <%# DataBinder.Eval(Container.DataItem, "Key") %>
            </td>
          </tr>
        </ItemTemplate>
        <FooterTemplate>
          </table>
        </FooterTemplate>
      </asp:Repeater>
    </form>
  </body>
</html>

Remember that the Repeater, like all bound controls, can be bound to any list element, not just the Hashtable.

Note, too, that nothing about the Repeater control necessitates outputting data in an HTML table; you can use the Repeater to render data as a comma-delimited list or as a single-column list with line break (BR) elements, for example.

Table Class

Member of System.Web.UI.WebControls.

The Table class is the ASP.NET server control abstraction of the HTML TABLE element.

Properties
AccessKey CssClass Rows
Attributes Enabled Site
BackColor EnableViewState Style
BackImageUrl Events TabIndex
BorderColor Font TagKey
BorderStyle ForeColor TagName
BorderWidth GridLines TemplateSourceDirectory
CellPadding HasChildViewState ToolTip
CellSpacing Height UniqueID
ChildControlsCreated HorizontalAlign ViewState
ClientID ID ViewStateIgnoresCase
Context IsTrackingViewState Visible
Controls NamingContainer Width
ControlStyle Page  
ControlStyleCreated Parent  
Methods
AddAttributesToRender FindControl OnItemCreated
AddParsedSubObject Finalize OnItemDataBound
ApplyStyle GetHashCode OnLoad
ClearChildViewState GetType OnPreRender
CopyBaseAttributes HasControls OnUnload
ClearChildViewState IsLiteralContent RaiseBubbleEvent
AddParsedSubObject LoadViewState Render
ClearChildViewState MapPathSecure RenderBeginTag
CreateChildControls MemberwiseClone RenderEndTag
CreateControlCollection MergeStyle RenderChildren
DataBind OnBubbleEvent RenderControl
Dispose OnDataBinding ResolveUrl
Equals OnInit SaveViewState
EnsureChildControls OnItemCommand ToString
    TrackViewState

TableCell Class

Member of System.Web.UI.WebControls.

The TableCell class is the ASP.NET server control abstraction of the HTML TD element.

Properties
AccessKey Enabled Site
Attributes EnableViewState Style
BackColor Events TabIndex
BorderColor Font TagKey
BorderStyle ForeColor TagName
BorderWidth HasChildViewState TemplateSourceDirectory
ChildControlsCreated Height Text
ClientID HorizontalAlign ToolTip
ColumnSpan ID UniqueID
Context IsTrackingViewState VerticalAlign
Controls NamingContainer ViewState
ControlStyle Page ViewStateIgnoresCase
ControlStyleCreated Parent Visible
CssClass RowSpan Width
Methods
AddAttributesToRender FindControl OnItemCreated
AddParsedSubObject Finalize OnItemDataBound
ApplyStyle GetHashCode OnLoad
ClearChildViewState GetType OnPreRender
CopyBaseAttributes HasControls OnUnload
ClearChildViewState IsLiteralContent RaiseBubbleEvent
AddParsedSubObject LoadViewState Render
ClearChildViewState MapPathSecure RenderBeginTag
CreateChildControls MemberwiseClone RenderChildren
CreateControlCollection MergeStyle RenderControl
DataBind OnBubbleEvent RenderEndTag
Dispose OnDataBinding ResolveUrl
Equals OnInit SaveViewState
EnsureChildControls OnItemCommand ToString
    TrackViewState

TableRow Class

Member of System.Web.UI.WebControls.

The Table class is the ASP.NET server control abstraction of the HTML TR element.

Properties
AccessKey Enabled Site
Attributes EnableViewState Style
BackColor Events TabIndex
BorderColor Font TagKey
BorderStyle ForeColor TagName
BorderWidth HasChildViewState TemplateSourceDirectory
Cells Height  
ChildControlsCreated HorizontalAlign ToolTip
ClientID ID UniqueID
Context IsTrackingViewState VerticalAlign
Controls NamingContainer ViewState
ControlStyle Page ViewStateIgnoresCase
ControlStyleCreated Parent Visible
CssClass   Width
Methods
AddAttributesToRender FindControl OnItemCreated
AddParsedSubObject Finalize OnItemDataBound
ApplyStyle GetHashCode OnLoad
ClearChildViewState GetType OnPreRender
CopyBaseAttributes HasControls OnUnload
ClearChildViewState IsLiteralContent RaiseBubbleEvent
AddParsedSubObject LoadViewState Render
ClearChildViewState MapPathSecure RenderBeginTag
CreateChildControls MemberwiseClone RenderChildren
CreateControlCollection MergeStyle RenderControl
DataBind OnBubbleEvent RenderEndTag
Dispose OnDataBinding ResolveUrl
Equals OnInit SaveViewState
EnsureChildControls OnItemCommand ToString
    TrackViewState

TextBox Class

Member of System.Web.UI.WebControls.

The TextBox class is the ASP.NET server control abstraction of both the HTML INPUT type text box as well as the TEXTAREA element.

Properties
AccessKey EnableViewState Style
Attributes Events TabIndex
AutoPostBack Font TagKey
BackColor ForeColor TagName
BorderColor HasChildViewState TemplateSourceDirectory
BorderStyle Height Text
BorderWidth   TextMode
ChildControlsCreated ID ToolTip
ClientID IsTrackingViewState UniqueID
Columns MaxLength  
Context NamingContainer ViewState
Controls Page ViewStateIgnoresCase
ControlStyle Parent Visible
ControlStyleCreated ReadOnly Width
CssClass Rows Wrap
Enabled Site  
Methods
AddAttributesToRender FindControl OnItemCreated
AddParsedSubObject Finalize OnItemDataBound
ApplyStyle GetHashCode OnLoad
ClearChildViewState GetType OnPreRender
CopyBaseAttributes HasControls OnUnload
ClearChildViewState IsLiteralContent RaiseBubbleEvent
AddParsedSubObject LoadViewState Render
ClearChildViewState MapPathSecure RenderBeginTag
CreateChildControls MemberwiseClone RenderChildren
CreateControlCollection MergeStyle RenderControl
DataBind OnBubbleEvent RenderEndTag
Dispose OnDataBinding ResolveUrl
Equals OnInit SaveViewState
EnsureChildControls OnItemCommand ToString
    TrackViewState

WebControl Class

Member of System.Web.UI.Webcontrol. Abstract class.

The WebControl class serves as the base class for Web controls.

Properties
AccessKey Enabled Style
Attributes EnableViewState TabIndex
BackColor Events TagKey
BorderColor Font TagName
BorderStyle ForeColor TemplateSourceDirectory
BorderWidth HasChildViewState ToolTip
ChildControlsCreated Height UniqueID
ClientID ID ViewState
Context IsTrackingViewState ViewStateIgnoresCase
Controls NamingContainer Visible
ControlStyle Page Width
ControlStyleCreated Parent  
CssClass Site  
Methods
AddAttributesToRender FindControl OnUnload
AddParsedSubObject   RaiseBubbleEvent
ApplyStyle GetHashCode Render
BuildProfileTree GetType RenderBeginTag
ClearChildViewState HasControls RenderChildren
CopyBaseAttributes IsLiteralContent RenderContents
CreateChildControls LoadViewState RenderControl
CreateControlCollection MemberwiseClone RenderEndTag
CreateControlStyle MergeStyle ResolveUrl
DataBind OnBubbleEvent SaveViewState
Dispose OnDataBinding  
EnsureChildControls OnInit ToString
Equals OnLoad TrackViewState
Finalize OnPreRender  
Events
DataBinding Init PreRender
Disposed Load Unload


 Python   SQL   Java   php   Perl 
 game development   web development   internet   *nix   graphics   hardware 
 telecommunications   C++ 
 Flash   Active Directory   Windows