Home > Articles

Controls

  • Print
  • + Share This
This chapter is from the book

Web Server Controls

Web server controls provide a higher level of abstraction than HTML server controls because their object model matches closely with the .NET Framework rather than matching with the requirements of HTML syntax.

The Web server controls have several advanced features, including

  • Web server controls provide a rich object model that closely matches with the rest of the .NET Framework.

  • Some Web server controls provide richer functionality, such as the Calendar control, AdRotator control, and so on, not available with HTML controls.

  • Web server controls have advanced features such as automatic browser detection, automatic postback, and event bubbling.

CAUTION

Because Web server controls are specifically designed to integrate well with the ASP.NET programming model, Exam 70-315 is likely to focus more on Web server controls than on HTML and HTML server controls.

Web server controls are declared in code explicitly by prefixing the class name of the Web server control with the namespace asp and separating both with a colon (:), as well as including the runat="server" attribute in its definition. For example, a Label Web server control can be declared in code as <asp:Label runat="server"/>.

Most Web server controls derive their functionality from the WebControl class of the System.Web.UI.WebControls namespace.

Table 3.1 lists some of the important properties inherited by Web server controls that derive from the WebControl class.

Table 3.1 Important Properties of the System.Web.UI.WebControls.WebControl Class

Property

Description

AccessKey

-Represents the single character keyboard shortcut key for quick navigation to the Web server control. The focus is moved to the Web server control when the Alt key and the key assigned to this property are pressed.

BackColor

Specifies the background color of the Web server control.

BorderColor

Specifies the border color of the Web server control.

BorderStyle

-Specifies the border style of the Web server control. The possible values are defined in the BorderStyle enumeration values; they are Dotted, Dashed, Double, Inset, NotSet, None, OutSet, Groove, Solid, and Ridge.

BorderWidth

Specifies the border width of the Web server control.

Controls

-Represents the collection of controls added to the Web server control as child controls. The WebControl class inherits this property from the Control class.

CssClass

-Represents the CSS class in which the Web server control is rendered.

Enabled

-Indicates whether the Web server control is enabled to receive focus.

EnableViewState

-Indicates whether view state is enabled for the Web server control. The WebControl class inherits this property from the Control class.

Font

-Specifies a FontInfo object that represents the font properties of a Web server control.

ForeColor

Specifies the color of text in the Web server control.

Height

Specifies the height of the Web server control.

ID

-Specifies an identifier for the Web server control. The WebControl class inherits this property from the Control class.

Parent

-Represents the parent control of the Web server control. The WebControl class inherits this property from the Control class.

Style

-Specifies the collection of CSS properties applied to the Web server control.

TabIndex

-Specifies the tab order of a Web server control. A negative value removes the control from the tab order.

ToolTip

-Specifies the pop-up text displayed by the Web server control when the mouse hovers over it.

Visible

-Indicates whether the Web server control is visible on the rendered page. The WebControl class inherits this property from the Control class.

Width

Specifies the width of the Web server control.


Common Web Server Controls

This section discusses some simple but commonly used controls available in the Visual Studio .NET toolbox. These controls are simple because they are usually rendered as single HTML elements and have only a few properties. Later in this chapter, you will learn about some advanced controls that provide myriad properties and render big chunks of HTML code.

Label Controls

A Label control is used to display read-only information to the user, label other controls, and provide the user with any useful messages or statistics. It exposes its text content through the Text property, which can be used to manipulate its text programmatically. The control is rendered as a <span> HTML element on the Web browser.

TextBox Controls

A TextBox control provides an area the user can use to input text. Depending on how you set the properties of this Web server control, you can either use it for multiline text input or use it like a password box that masks the characters entered by the user. Thus, this server control can be rendered as three types of HTML elements: <input type="text">, <input type="password">, and <textarea>. Table 3.2 summarizes the important members of the TextBox class.

Table 3.2 Important Members of the TextBox Class

Member

Type

Description

AutoPostBack

Property

Indicates whether the Web form should be posted to the server automatically whenever the data in the text box is changed. It works only if the browser supports client-side scripting.

Columns

Property

Specifies the width, in characters, of the text box.

MaxLength

Property

Specifies the maximum number of characters allowed to be entered by the user. The default value is 0. It works only if the TextMode property is not set to MultiLine.

ReadOnly

Property

Indicates whether the contents of the text box are read-only—that is, they cannot be modified. The default value is false.

Rows

Property

Specifies the height in characters of the multiline text box. The default value is 0. It works only if the TextMode property is set to MultiLine.

Text

Property

Specifies the text contained in the text box.

TextChanged

Event

Occurs when the value of the Text property changes. TextChanged is the default event for the TextBox class.

TextMode

Property

Represents the type of the text box to be rendered in the Web page. It can be displayed in one of these TextBoxMode enumeration values: MultiLine (the text box can accept multiple lines of input), Password (a single-line text box with each character masked), and SingleLine (a single-line text box with normal text displayed).

Wrap

Property

Specifies whether the control can automatically wrap words to the next line. The default value is true. It works only if the TextMode property is set to MultiLine.


Image Controls

An Image Web server control displays images from bitmap, JPEG, PNG, and GIF files. The control is rendered as an <img> HTML element on the Web page. Table 3.3 summarizes the important properties of the Image class.

Table 3.3 Important Members of the Image Class

Property

Description

AlternateText

-Specifies the text displayed in place of the Image Web server control when the image is being downloaded, the image is unavailable, or the browser doesn't support images. The specified text is also displayed as a ToolTip if the browser supports the ToolTip feature.

ImageAlign

-Indicates the alignment of the Image Web server control relative to other elements on the Web page. It can be set to one of these ImageAlign enumeration values: AbsBottom, AbsMiddle, Baseline, Bottom, Left, Middle, NotSet (default value), Right, TextTop, and Top.

ImageUrl

-Represents the URL (location) of the image the Image Web server control displays. The URL can be either relative or absolute.


Checkbox and RadioButton Controls

A CheckBox control enables the user to select one or more options from a group of options, and a group of RadioButton controls is used to select one out of several mutually exclusive options. If you want to place two groups of RadioButton controls on a form and have each group allow one selection, radio button controls of each group should individually set their GroupName property to indicate the group to which they belong. The check box and radio button Web server controls are rendered as <input type="checkbox"> and <input type="radio"> HTML elements on the Web page, respectively.

The RadioButton class inherits from the CheckBox class, and both of them share the same members—except the GroupName property available in the RadioButton class.

Table 3.4 summarizes the important members of the CheckBox and RadioButton classes.

Table 3.4 Important Members of the CheckBox and RadioButton Classes

Member

Type

Description

AutoPostBack

Property

Indicates whether the Web form should be posted to the server automatically when the control is clicked. It works only if the browser supports client-side scripting.

Checked

Property

Returns true if the control has been checked. Otherwise, it returns false.

CheckedChanged

Event

Occurs every time a control is checked or unchecked. CheckedChanged is the default event for the CheckBox class.

Text

Property

Specifies the text displayed along with the control.

TextAlign

Property

Specifies the alignment of the text displayed along with the control. It can be one of the TextAlign enumeration values: Left (the text is displayed on the left of the control) or Right (by default, the text is displayed to the right of the control).


Button, LinkButton, and ImageButton Controls

A button is used to initiate a specific action when clicked by the user. Each of the three button controls is different in its appearance and therefore is rendered differently on the Web page. They include

  • Button—This control is displayed as a push button on the Web page and is rendered as an <input type="submit"> HTML element.

  • LinkButton—This control is displayed as a hyperlink on the Web page and is rendered as an <a> HTML element.

  • ImageButton—This control is displayed as an image button on the Web page and is rendered as an <input type="image"> HTML element.

All three button Web server controls behave in the same way: They all post the form data to the Web server when they are clicked. However, the LinkButton control works only if client-side scripting is enabled in the Web browser.

Table 3.5 summarizes the important members that are applicable to the Button, LinkButton, and ImageButton classes.

Table 3.5 Important Members of the Button, LinkButton, and ImageButton Classes

Member

Type

Description

CausesValidation

Property

-Indicates whether the validation should be performed when the button control is clicked. Validation is discussed in detail later in this chapter.

Click

Event

-Occurs when the button control is clicked. Click is the default event of all three classes. This event is mostly used for submit buttons.

Command

Event

-Occurs when the button control is clicked. This event is mostly used for command buttons. The event handler receives an object of type CommandEventArgs that contains both the CommandName and CommandArgument properties containing event-related data.

CommandArgument

Property

-Specifies the argument for a command. It works only if the CommandName property is set. The property is passed to the Command event when the button is clicked.

CommandName

Property

-Specifies the command name for the button. The property is passed to the Command event when the button is clicked.

Text

Property

-Specifies the text displayed on a button. The ImageButton class does not have this property.


By default, any type of button Web server control is a submit button. If you specify a command name via the CommandName property, the button control then becomes a command button.

A command button raises the Command event when it is clicked. The button passes the CommandName and CommandArgument properties encapsulated in a CommandEventArgs object to the event handlers. The Command button is useful when you want to pass some event-related information to the event handler.

The following example creates a Web form that uses some of the common Web server controls discussed in the previous sections. Do the following:

  1. Launch Visual Studio .NET and create a new Visual C# Project based on the ASP.NET Web Application template. Specify the location of the project as http://localhost/ExamCram/315C03.

  2. Add a new Web form to the project and name it Example3_1.aspx. Delete the default form, WebForm1.aspx, from the project.

  3. Use the Web Forms controls to create a user interface similar to Figure 3.1.

  4. Figure 3.1Figure 3.1 Example3_1.aspx uses Web server controls to create the user interface.

  5. Set the ID property of the Subscribe button to btnSubscribe and set the ID property of the Name text box to txtName.

  6. Before the Name label and text box on the page, place a Label Web server control and set its ID property to lblMessage.

  7. Double-click the Subscribe button. You are taken to Code view, where an event handler for the btnSubscribe's Click event is added. Add the following code in the event handler:

  8. private void btnSubscribe_Click(object sender, System.EventArgs e)
    {
      // Display a personalized thank you message 
      lblMessage.Text = txtName.Text + 
        ", thank you for subscribing to \"" +
        ddlNewsletter.SelectedItem + "\".";
    }
  9. Run the project; then fill in details in the Web page and click the Subscribe button.

CAUTION

When you create a Web form, all the user interface elements are contained in the <form runat="server"> control. The form, along with all its controls, is accessible to ASP.NET only when the <form> element has a runat="server" attribute attached to it. Only one <form runat="server"> control can exist on a Web page.

You can note from the btnSubscribe_Click() method that Web server controls provide a very consistent model for programming. The text of the Label control can be accessed using the obvious Text property rather than the InnerText property, as is the case with HTML server controls.

Event Handling for Web Server Controls

The following list summarizes the features of event handling as it relates to Web server controls:

  • Intrinsic events—Web server controls have a set of intrinsic events available to them. Some simple controls such as Button provide only two intrinsic events—Click and Command—whereas advanced controls such as DataGrid provide as many as nine intrinsic events.

  • Event arguments—By convention, all events in the .NET Framework pass two arguments to event handlers—the object that raised the event and an object containing any event-specific information. Most events do not have any event-specific information; therefore, they just pass an object of type System.EventArgs as the second argument. Some Web server controls, however, pass event-specific data to their event handlers using a type extended from System.EventArgs. One such example is the ImageButton Web server control in which the second argument is of the type ImageClickEventArgs. The ImageClickEventArgs objects encapsulate information about the coordinates at which the user has clicked the ImageButton.

  • AutoPostBack—Usually, the change events of server controls are cached and fired on the Web server at a later stage when the page is posted back as a result of a Click event of button controls. Some Web server controls, such as DropDownList, CheckBox, and so on, have a property named AutoPostBack. When this property is set to true, it causes an immediate postback of the page when the value of the control is changed. This enables the Web server to immediately respond to change events without waiting for a Click event to cause a page postback. In HTML, only a few controls inherently submit a form; to enable other controls to cause a postback, ASP.NET attaches a small client script with the control.

  • Bubbled events—Some advanced Web server controls, such as DataGrid, can also contain other controls (such as a button). DataGrid controls usually display dynamically generated data, and if each row of the DataGrid contains a button, you might have a variable number of button controls. Writing an individual event handler for each button control in this case is a tedious process. To simplify event handling, controls such as DataGrid support bubbling of events. In bubbling, all events raised at the level of child control are bubbled up to the container control, where the container control can raise a generic event in response to the child events.

Client-side Event Handling for Web Server Controls

ASP.NET provides a set of validation controls that enable you to easily validate user input without manual client-side programming or frequent round trips to the server. However, you might still want to use some amount of client-side programming in your code, especially to handle frequently occurring events such as MouseMove or KeyPress.

ASP.NET already uses client-side event handling to perform automatic postback operations; therefore, the preferred way to add client-side event handling code for Web server controls is via the Attributes property of the Web server controls. For example, the following code fragment attaches the someClientCode() client-side method to the onMouseOver attribute of the btnSubmit button:

btnSubmit.Attributes.Add("onMouseOver", "someClientCode();")

The List Controls

The category of list controls includes the DropDownList, ListBox, CheckBoxList, and RadioButtonList controls. These controls display a list of items from which the user can select, and they inherit from the abstract base ListControl class. Table 3.6 summarizes the important members of the ListControl class with which you should be familiar.

Table 3.6 Important Members of the ListControl Class

Member

Type

Description

AutoPostBack

Property

Indicates whether the Web form should be posted to the server automatically whenever the list selection is changed. It works only if the browser supports client-side scripting.

Items

Property

Specifies a collection of items in the list control.

SelectedIndex

Property

Specifies an index of the currently selected item. The default value is –1, which means that no item is selected in the list control.

SelectedIndexChanged

Event

Occurs when the SelectedIndex property changes. SelectedIndexChanged is the default event for the list controls.

SelectedItem

Property

Specifies the currently selected item.


Although these controls inherit their basic functionality from the ListControl class, they display lists of items in different styles and enable single or multiple modes of selection.

A DropDownList Web server control allows you to select only a single item from the drop-down list. This Web server control is rendered as a <select> HTML element, and its items are added as <option> elements in the <select> element.

CAUTION

The default value of the SelectedIndex property of the ListControl object is -1, which indicates that no item is selected in the list control. However, the DropDownList control overrides this property and sets the default value to 0, which indicates the first item in the list. This ensures that an item is always selected in the drop-down list.

A ListBox Web server control allows you to select single or multiple items from the list of items displayed in the list box. It is rendered as a <select> or <select multiple="multiple"> HTML element depending on whether single or multiple selection is allowed. The items are added as <option> elements in the <select> element. The ListBox class adds two more properties to enable it to select multiple items, as shown in Table 3.7.

Table 3.7 Important Members of the ListBox Class

Property

Description

Rows

Represents the number of rows to be displayed in the list box. The default value is 4. The value of this property must be between 1 and 2000.

SelectionMode

Indicates the mode of selection allowed in the list box. It can be one of the ListSelectionMode enumeration values: Multiple or Single (default).


The CheckBoxList and RadioButtonList Web server controls display lists of check boxes and radio buttons, respectively. The CheckBoxList and RadioButtonList controls render each list item as <input type="checkbox"> and <input type="radio"> HTML elements, respectively. The list items are displayed in a table or without a table structure, depending on the layout sel-ected.

Table 3.8 summarizes the important properties of the CheckBoxList and RadioButtonList classes that relate to the formatting capabilities of these Web server controls.

Table 3.8 Important Formatting Properties of the CheckBoxList and RadioButtonList Classes

Property

Description

CellPadding

Specifies the distance in pixels between the border and the contents (that is, check box or radio button) of the list control.

CellSpacing

Specifies the distance in pixels between the items (that is, check box or radio button) of the list control.

RepeatColumns

Specifies the number of columns to be displayed in the list control.

RepeatDirection

Specifies the direction of layout of the items in the list control. It can be one of the RepeatDirection enumeration values: Horizontal or Vertical (default).

RepeatLayout

Specifies the layout method of the items in the list control. It can be one of the RepeatLayout enumeration values: Flow (the items are not displayed in a table structure) or Table (default; the items are displayed in a table structure).

TextAlign

Specifies the alignment of the text displayed along with the individual items in the list control. It can be one of the TextAlign enumeration values: Left (the text is displayed on the left of the item control) and Right (default; the text is displayed on the right of the item control).


CAUTION

List controls such as ListBox and CheckBoxList enable you to make multiple selections from the list controls. When these controls allow multiple selections, the SelectedIndex and SelectedItem properties return the index of the first selected item and the first selected item, respectively. You must iterate through the ListItemCollection controls available via the Items property and check whether each item's Selected property is true to retrieve the items selected by the user.

This example shows how to use the list controls:

  1. In the project 315C03, add a new Web form named Example3_2.aspx.

  2. Add a Label control on the form and change its Text property to Tourist Interests Survey. Set the font size to Large. Then add another Label control and change its Text property to Which national parks are you interested in visiting?. Set the font size to Medium.

  3. Drag a ListBox control onto the form and change its ID to lbParks. Using the Properties window, select the Items property and click the ellipse button (...). This opens the ListItem Collection Editor. Enter names for a few national parks. Set the SelectionMode property of the lbParks list box to Multiple.

  4. Drag a CheckBoxList control (cblActivities) and a RadioButtonList control (rblVacation) to the form. Set the RepeatColumn property for both controls to 2. Add a couple of label controls and arrange the controls as shown in Figure 3.2.

  5. Figure 3.2Figure 3.2 Example3_2.aspx uses list controls to accept user input.

  6. Place an ImageButton control (ibSubmit) on the Web form and set its ImageUrl property to a GIF file representing a button. Place a Label control (lblSummary) at the bottom of the form (refer to Figure 3.2).

  7. Add the following using directive at the top of the code-behind file:

  8. using System.Text;
  9. Double-click the ibSubmit image button to attach an event handler with its Click event. Add the following code to the event handler:

  10. private void ibSubmit_Click(object sender, 
      System.Web.UI.ImageClickEventArgs e)
    {
      // Create a StringBuilder object that you
      // will use to efficiently concatenate messages
      StringBuilder sb = new StringBuilder();
      sb.Append("<h3>Thank You! The following data ");
      sb.Append(" entered by you has been recorded</h3>");
      sb.Append("<h4>Selected Parks: </h4>");
    
      // Because the SelectionMode property of lbParks is Multiple, 
      // you need to iterate through its Items collection to 
      // individually gather the selected national parks
      foreach (ListItem li in lbParks.Items)
        if (li.Selected)
          sb.Append(String.Format("{0}<BR>", li.Text));
    
      sb.Append("<h4>Selected Activities: </h4>");
      // Multiple activities can be selected by the user. Therefore, 
      // you need to iterate through the complete Items collection to 
      // individually find the selected activities
      foreach (ListItem li in cblActivities.Items)
        if (li.Selected)
          sb.Append(String.Format("{0}<BR>", li.Text));
    
      sb.Append("<h4>Average Vacation Size: </h4>");
      // Only one item can be selected from a RadioButtonList
      sb.Append(rblVacation.SelectedItem.Text);
    
      // Copy the messages to the bottom label control
      lblSummary.Text = sb.ToString();
    }
  11. Set Example3_2.aspx as the start page of the project, build the project, and then run it. Fill the form and submit the details by clicking the Submit image button. You should see a summary message displaying all the selected items at the bottom of the form.

In the previous example, to find the selected items in the list controls in which multiple items can be selected, you must iterate through the ListItemCollection object corresponding to the list control. For those controls in which only single selection is allowed, you can simply use the SelectedItem property to find the selected item.

PlaceHolder and Panel Controls

A PlaceHolder Web server control enables you to reserve an area on a Web page. It also allows you to add controls dynamically in a Web page at the area it has reserved.

The PlaceHolder Web server control inherits from the System.Web.UI.Control class and does not share the common properties that Web server controls from the WebControl class do. The control also does not define any new properties, events, or methods and does not render any HTML element for itself.

A Panel Web server control acts as a container for other controls in the Web page and can be used to organize controls in the Web page. It can be used to hide or show controls contained in the panel in the Web page. Controls can also be added programmatically to the panel. The Panel Web server control is rendered as a <div> HTML element on the Web page.

This example shows how to use a Panel control to load controls dynamically on a form at runtime:

  1. Add a new Web form (Example3_3.aspx) to the project.

  2. Place a Label control on the form. Set its Text property to Travel Expense Calculator and set the font size to Medium. Place a horizontal rule after the label.

  3. Place two more Label controls on the form, setting their Text properties to Associate Name and Number of days, respectively. Add a TextBox control and set its ID property to txtName.

  4. Add a DropDownList control, setting its ID property to ddlDays and its AutoPostBack property to true. Use the ListItem Collection Editor to add values from 0 to 5 in the drop-down list.

  5. At the bottom of the form, place a Panel control and set its ID property to pnlDynamic.

  6. Switch to Code view and add the following code in the Page_Load() event handler:

  7. // Use the Page_Load event to load the dynamically created controls
    // so that they are available prior to rendering
    private void Page_Load(object sender, System.EventArgs e)
    {
      // Get the value selected by the user in the drop-down list
      int intDays = Convert.ToInt32(ddlDays.SelectedItem.Value);
      // Create text boxes to allow entering the travel expenses
      for (int i = 1; i <= intDays; i++)
      {
        LiteralControl lcExpenseCaption = new LiteralControl();
        lcExpenseCaption.Text =
         String.Format("Travel Expense for Day-{0} ", i);
        // Create a text box control
        TextBox txtExpense = new TextBox();
        // Set the ID property of the text box
        txtExpense.ID = String.Format("Expense{0}", i);
        HtmlControl lcBreak = new HtmlGenericControl("br");
        pnlDynamic.Controls.Add(lcExpenseCaption);
        // Add the text box to the panel. if you omit this step, 
        // the text box is created but not displayed
        pnlDynamic.Controls.Add(txtExpense);
        pnlDynamic.Controls.Add(lcBreak);
      }
      // Display a link button that allow users to post
      // the expenses after they have entered the data
      if(intDays>0)
      {
        LinkButton lbtnSubmit = new LinkButton();
        lbtnSubmit.Text = "Submit Expenses";
        // Add an event handler to the dynamically created link button
        lbtnSubmit.Click += new EventHandler(lbtnSubmit_Click);
        pnlDynamic.Controls.Add(lbtnSubmit);
        HtmlControl lcBreak = new HtmlGenericControl("br");
        pnlDynamic.Controls.Add(lcBreak);
      }
    }
  8. Add another method that handles the Click event for the dynamic link button:

  9. // Handles the Click event for the dynamically created link button
    private void lbtnSubmit_Click(object sender, System.EventArgs e)
    {
      double dblExpenses = 0;
      int intDays = Convert.ToInt32(ddlDays.SelectedItem.Value);
      // Find sum of all expenses
      for (int i = 1; i <= intDays; i++)
      {
        // Find control in the collection of controls 
        TextBox txtExpense = (TextBox)
          pnlDynamic.FindControl(String.Format("Expense{0}", i));
        dblExpenses += Convert.ToDouble(txtExpense.Text);
      }
      // Display the results
      Label lblResults = new Label();
      lblResults.Text = String.Format("{0}, a sum of ${1} has been " +
        "credited to your account.", txtName.Text, dblExpenses);
      pnlDynamic.Controls.Add(lblResults);
    }
  10. Set Example3_3.aspx as the start page and run the project. Enter a name for the associate and select 3 from the drop-down list. You'll see that three text box controls have been created for you to enter travel expenses. A link button enables you to post the expenses to the Web server. Enter some values for the expenses and click the link button. Note that the expenses were all summed and a message is displayed.

TIP

Because the Web pages are re-created with each request, you should always use the Load event handler for loading the controls dynamically on the Web page. This event handler ensures that the controls are created each time the page is loaded. In addition, ASP.NET automatically maintains state for the controls that are loaded dynamically.

TIP

After you create a control, you must remember to add it to one of the container controls on the Web page. If you just create a control but forget to add it to the container control, your control will not be rendered in the page.

The AdRotator Control

The AdRotator Web server control provides a convenient mechanism for displaying advertisements randomly on a Web page. The advertisements are detailed in an Extensible Markup Language (XML) file. The following listing shows a partial sample advertisement file:

<?xml version="1.0" ?>
<Advertisements>
  <Ad>
    <ImageUrl>que.gif</ImageUrl>
    <NavigateUrl>http://www.quepublishing.com
    </NavigateUrl>
    <AlternateText>Que Publishing</AlternateText>
    <Impressions>40</Impressions>
    <Keyword>Books</Keyword>
    <Specialization>Certification Books</Specialization>
   </Ad>
   ...
</Advertisements>

The advertisements are individually stored in <Ad> elements, which specify the information for each advertisement by a collection of elements.

The AdRotator control is rendered as an <a> anchor HTML element with an embedded <img> image HTML element for displaying the image on the Web page. Table 3.9 summarizes the important members of the AdRotator class with which you should be familiar.

Table 3.9 Important Members of the AdRotator Class

Member

Type

Description

AdCreated

Event

Occurs when the AdRotator control is created.

AdvertisementFile

Property

Specifies the location of an XML file that stores the advertisement information.

KeywordFilter

Property

Specifies the keyword (group name) on which the advertisements need to be filtered. The property relates to the <Keyword> element in an <Ad> element in the advertisement file.

Target

Property

Specifies the target window or frame in which the contents of the linked Web page will be displayed when the AdRotator control is clicked. Some of the possible values are _blank (new window), _parent (parent frame set), _self (current position in the window), and _top (current window).


CAUTION

When the KeywordFilter property of an AdRotator control is set to a keyword that does not correspond to any <Keyword> element in the XML advertisement file, AdRotator displays a blank image in place of the advertisement and a trace warning is generated.

The AdCreated event passes an object of type AdCreatedEventArgs that contains event-related data. The object consists of the following four properties: AdProperties, AlternateText, ImageUrl, and NavigateUrl. AdProperties contains a collection of key/value pairs representing all the elements (including custom) defined for the current <Ad> element.

The Calendar Control

The Calendar Web server control displays a calendar on the Web page and enables you to select a day, week, month, or range of days. You can customize the appearance of the control and even add custom content for each day. The control generates events when a selection changes or the visible month is changed in the Calendar control. The Calendar control is rendered as a <table> HTML element on the Web page. Please refer to the Microsoft .NET Framework documentation for the complete list of properties and events for the Calendar control.

  • + Share This
  • 🔖 Save To Your Account