Controls for MCAD Exam 70-315

Date: Nov 13, 2003

Return to the article

Controls are the building blocks of a GUI. In this sample chapter, you'll work with HTML controls, HTML server controls, Web server controls, and validation controls to create the user interface for a Web application. You will also learn about user controls, composite controls, and custom controls, which enable you to extend the existing controls to achieve custom functionality.

Chapter 3:Controls

Terms you'll need to understand:

Techniques you'll need to master:

Controls are the building blocks of a GUI. In this chapter, you'll work with HTML controls, HTML server controls, Web server controls, and validation controls to create the user interface for a Web application. You will also learn about user controls, composite controls, and custom controls, which enable you to extend the existing controls to achieve custom functionality.

HTML Controls

HTML controls represent common HTML elements and are available through the HTML tab of the Visual Studio .NET toolbox. You can drag these controls to a Web form and set their properties in the Properties window. An HTML control, such as Text Field or Label, is converted to its appropriate HTML equivalent, such as the <INPUT> and <DIV> element, respectively, in the source code of the ASPX file. All the HTML controls are automatically placed inside an HTML <FORM> element.

HTML controls are only of little use in ASP.NET programs because they can't be accessed from the server-side code. ASP.NET provides two other sets of controls that are much better suited for server-side programming: HTML server controls and Web server controls.

HTML Server Controls

HTML server controls are similar to HTML controls with the added feature of server-side availability. You can convert any HTML control to run as an HTML server control by adding a runat="server" attribute to its declaration. You can accomplish the same task visually by right-clicking an HTML control and selecting Run As Server Control from the shortcut menu.

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

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

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.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:

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.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.

User Input Validation

ASP.NET provides a set of Web server controls called validation controls that provide sophisticated validation on both the client side and the server side depending on the validation settings and the browser's capabilities.

CAUTION

ASP.NET ensures that validations are performed on the server side even if they were already performed on the client side. This ensures that validations are not bypassed if a malicious user circumvents client-side validation. If the client-side validation fails, the server-side validation is never performed.

ASP.NET validation controls derive their basic functionality from the BaseValidator abstract class available in the System.Web.UI.WebControls. Table 3.10 lists some of the important members of the BaseValidator class.

Table 3.10 Important Members of the BaseValidator Class

Member

Type

Description

ControlToValidate

Property

Specifies the ID of the input server control that needs to be validated. This property should be passed a valid ID. However, it can be empty for a custom validation control.

Display

Property

Specifies how to display the inline error message contained in the Text property. It can be any of the ValidatorDisplay enumeration values, including Dynamic (the space is dynamically added), None (the message is never displayed), and Static (the space is occupied when the validation control is rendered).

EnableClientScript

Property

Indicates whether the client-side validation is enabled. The default is true.

Enabled

Property

Indicates whether the validation control is enabled. If false, the validation is never performed.

ErrorMessage

Property

Represents the error message to be displayed by the ValidationSummary control when the validation fails. If the Text property is not set, this message is displayed inline.

ForeColor

Property

Specifies the foreground color in which the message is displayed when the validation fails. The default value is Color.Red.

IsValid

Property

Indicates whether the input control passes the validation.

Text

Property

Specifies the text of the error message displayed by the validation control inline.

Validate()

Method

Performs the validation on the associated input control and then updates the IsValid property with the result of the validation.


CAUTION

When you set the Enabled property to false for a validation control, the validation on the control is performed neither at the client side nor at the server side. If you want to disable validation only at the client side, you should set the EnableClientScript property of the validation control to false.

CAUTION

When the CausesValidation property is set to false, it prevents client-side and server-side validations from occurring. This property is ideal for the Cancel and Reset buttons in a Web page. The Button, LinkButton, ImageButton, HtmlButton, HtmlInputButton, and HtmlInputImage controls contain this property.

Using the Page.Validate() Method and Page.IsValid Property

As you can see in Table 3.10, each validation control maintains an IsValid property that indicates the status of the validation test. The Page control that hosts the Web controls also contains a property called IsValid that indicates the status of the validation for the whole page. When all the validation controls on the Web form set their IsValid properties to true, Page.IsValid also becomes true. If the validation fails on any of the validation controls, Page.IsValid is false.

The Page class maintains a collection of the validation controls on a Web page that can be accessed through its Validators property. The Page class also contains a Validate() method that invokes the Validate() method of all the validation controls in the page. The Page.Validate() method is used to perform validation programmatically on all the validation controls of a Web page.

ASP.NET validation is performed after page initialization—that is, after the Load event of the Page is raised but before the event-handling code is called. Therefore, you cannot know the status of the validation test in the Page_Load() event handler, and the data posted from the client should not be accessed at this stage of page processing. You should always try to use data posted from the client in event-handling code such as the Click event of the Button control. However, if you need to access client-posted data in the Page_Load() event handler, you can do so by calling the Page.Validate() method.

Validation Web Server Controls

ASP.NET provides the following validation controls that derive their functionality from the BaseValidator class: RequiredFieldValidator, RegularExpressionValidator, RangeValidator, CompareValidator, and CustomValidator.

These validation controls are usually associated with the input server controls on which the validation needs to be performed. For validation to work properly, the validation control and the input server control should be placed in the same container control. The validation controls are usually placed next to the associated input control so that you can display error messages or indicators next to the input control. You can associate any number of validation controls with an input server control. For example, the Date of Hire input field in an Add Employee form cannot be left empty (validated through the RequiredFieldValidator control) and should be less than or equal to the current date (validated through the CompareValidator control). You'll learn more about the validation Web server controls in the following sections.

The RequiredFieldValidator Control

The RequiredFieldValidator control can be used to check whether the input control contains an entry. It makes the associated input control a required field in the Web page and ensures that some input data is passed to it. The control also trims whitespace prior to checking for the required field entry.

The RequiredFieldValidator control contains a special property called InitialValue that can be passed the initial value of the associated input control. During validation, if the input control's validation property contains the same initial value or is empty, it sets IsValid to false, indicating that the validation failed. For example, a drop-down list might allow users to select a state and when the page loads, its initial value could be Select a State. If a RequiredFieldValidator control is associated with the drop-down list control, its InitialValue property can be set to the same initial value of the drop-down list—Select a State. When the validation occurs, the validation control ensures that the item selected in the drop-down list is not the item set in the InitialValue property of the validation control.

CAUTION

The RequiredFieldValidator control is the only validation control that ensures that the associated input control is a required field. Other validation controls assume the input control's data to be valid if it is left blank.

The RegularExpressionValidator Control

The RegularExpressionValidator control checks whether the associated input control's validation property matches a specified pattern. This pattern is specified by the ValidationExpression property using a regular expression. If you are not familiar with regular expressions, you can find more information in the Microsoft .NET Framework documentation.

The RangeValidator Control

The RangeValidator control is used to check whether the input control contains a value in the specified range. You can check the range of values against different data types such as String, Date, and Integer.

Table 3.11 shows the important properties of the RangeValidator class.

Table 3.11 Important Properties of the RangeValidator Class

Property

Description

MaximumValue

Specifies the upper value of the validation range.

MinimumValue

Specifies the lower value of the validation range.

Type

Specifies the data type to be used when comparing the data.


The CompareValidator Control

The CompareValidator control is used to compare the input server control's value against another value. The CompareValidator control can compare against a value specified to the validator control or against the value of another input control. The comparison can be made with different comparison operators such as equal, greater than, and so on. A special comparison operation can be used to verify that the associated input control's value is in the specified data type. You can make comparisons against various data types, such as String, Date, Integer, and so on.

Table 3.12 shows the important properties of the CompareValidator class.

Table 3.12 Important Properties of the CompareValidator Class

Property

Description

ControlToCompare

-Specifies the input server control against whose value the associated input control is to be validated.

Operator

Specifies the comparison operation to be performed.

Type

Specifies the data type to be used when comparing the data.

ValueToCompare

-Specifies the value against which the associated input control is to be validated.


CAUTION

If both the ControlToCompare and ValueToCompare properties are set for a CompareValidator control, the ControlToCompare property takes precedence.

TIP

If the Operator property of a CompareValidator is set to DataTypeCheck, the ControlToCompare and ValueToCompare properties are ignored. The validator control tries to convert the input control value to the data type specified by the Type property and sets the IsValid property with the result.

This example shows how to use the RangeValidator and CompareValidator controls on a Web form:

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

  2. Insert a table by selecting Table, Insert, Table. This opens the Insert Table dialog box. Create a table of two rows and two columns with a border size of 0 in the form. Add two Label controls and two TextBox controls (txtDate and txtTickets) to the table. Drag three Label controls and a Button control (btnSubmit) onto the Web form and arrange the controls.

  3. Place one RangeValidator control (rvDate) on the table next to the txtDate control. Set its ControlToValidate property to txtDate, its Type property to Date, its MinimumValue property to 09/01/2003, its MaximumValue property to 09/30/2003, and its ErrorMessage property to an appropriate error message.

  4. Place one CompareValidator control (cvTickets) on the table next to the txtTickets control. Set its ControlToValidate property to txtTickets, its Type property to Integer, its Operator property to GreaterThanEqual, its ValueToCompare property to 2, and its ErrorMessage property to an appropriate error message.

  5. Set the ASPX page as the start page; then build and run the project. Enter an invalid date and an invalid number of tickets and click the Submit button. You will see the error messages from the RangeValidator and CompareValidator controls (see Figure 3.3). Enter valid values and click the Submit button. The form posts back successfully.

The CustomValidator Control

The CustomValidator control allows you to build a validation control for a custom specification. You can perform any custom validation both at the server side and at the client side with the help of this validation control.

This control exposes a property called ClientValidationFunction that specifies the name of the client script function to be executed for validation on the client side. This custom validation function is passed two arguments: The first one is the custom validator control, and the second argument is an object that contains two properties—IsValid and Value. The Value property contains the value that is to be validated, and the IsValid property is used to set the result of the validation.

Figure 3.3 Use the RangeValidator control to ensure that a control's value is in the specified range, and use the CompareValidator control to compare the control's value with a specified value.

At the server side, during the validation on the server, the validation control fires a ServerValidate event. An event handler containing the custom validation code is added to this event to perform validation on the server. The event sends a ServerValidateEventArgs object containing event-related data. This object contains two properties: The Value property contains the value of the control that is to be validated, and the IsValid property is used to set the result of the validation.

The ValidationSummary Control

The ValidationSummary control is used to display a summary of all the validation errors of a Web page. It displays the ErrorMessage property of the validation controls in the summary. If the ErrorMessage property is not set, the Text property is displayed as error messages for all the validation controls whose validations fail.

Table 3.13 shows the important properties of the ValidationSummary class.

Table 3.13 Important Properties of the ValidationSummary Class

Property

Description

DisplayMode

Specifies the way in which the validation summary is displayed. Values are defined by the ValidationSummaryDisplayMode enumeration and include BulletList (default), List, and SingleParagraph.

EnableClientScript

Indicates whether the validation summary control should generate client-side script to update itself. The default is true.

ForeColor

Specifies the foreground color in which the error messages are displayed when the validation fails. The default value is Color.Red.

HeaderText

Specifies the header text of the validation summary control.

ShowMessageBox

Indicates whether the validation summary messages should be displayed in a message box. The default is false.

ShowSummary

Indicates whether the validation summary messages should be displayed inline in the validation summary control. The default is true.

Cascading Style Sheets

A Cascading Style Sheet (CSS) contains style definitions that are applied to elements in an HTML document. The information inside a CSS defines how HTML elements are displayed and where they are positioned on a Web page. With CSS, you can store all the formatting information for a Web application in a single CSS file and then instruct all the Web forms to use that file for formatting settings. This offers the following advantages:

You can use the GUI-based CSS designer available in Visual Studio .NET to easily create the CSS files and attach them to your Web application. The Web form does not automatically read the information in CSS files, though; you need to link a CSS file with the ASPX page using the HTML <link> element.

CSS also enables you to define custom style classes. A custom style class is applied to a Web server control using the CssClass property and to an HTML server control using the Class property. For example, if you have the following definition in the CSS file associated with the ASPX page and you want to apply this style to a TextBox Web server control, you simply need to change the CssClass property of the TextBox Web server control to TextBoxStyle. Here's how you do so:

.TextBoxStyle
{
  border-right: blue double;
  border-top: blue double;
  font-size: medium;
  border-left: blue double;
  color: white;
  border-bottom: blue double;
  background-color: #6699cc;
}

Exam Prep Questions

Question 1

Your company has recently decided to upgrade its supplier evaluation system from ASP to ASP.NET. You want to convert old ASP pages to Web forms as quickly as possible. You have noticed that you can keep the existing user interface but want to move the business logic to code-behind files. Which of the following approaches provides the smoothest migration path?

  1. Continue to use HTML controls on ASP.NET Web forms. In the code-behind files, rewrite all business logic using C#.

  2. Apply the runat="server" attribute to all HTML controls. In the code-behind files, rewrite all business logic using C#.

  3. Use ASP.NET Web server controls instead of HTML controls. In the code-behind files, rewrite all business logic using C#.

  4. Continue to use HTML controls for labels and text boxes but convert all Button controls to Web server controls. In the code-behind files, rewrite all business logic using C#.

Answer B is correct. Use of HTML server controls provides the easiest migration path for an existing HTML-based user interface. It does not take much effort to convert an HTML control to an HTML server control because you only need to add a runat="server" attribute to it. Answers A and D are incorrect because HTML controls are not directly available to the ASP.NET pages. Answer C is incorrect because ASP.NET Web server controls do not map one-to-one with HTML controls and will require additional conversion efforts.

Question 2

SurveyComm, Inc., is a marketing company that organizes surveys on behalf of large consumer goods companies. The surveys involve a large number of participants. SurveyComm recently decided to put its surveys online. You work as a Web developer for SurveyComm, and your responsibility is to design one of the online survey forms using ASP.NET. One of the questions in the survey form has a large number of options, and users can select multiple options as an answer to this question. You have used the CheckBoxList Web server control to display the options. In the code, you want to get all the options selected by the user so that you can store them in a database. Which of the following techniques should you use?

  1. Use the SelectedItem property of the CheckBoxList control.

  2. Use the SelectedIndex property of the CheckBoxList control.

  3. Use the DataValueField property of the CheckBoxList control.

  4. Use the Items property of the CheckBoxList control.

Answer D is correct. You should use the Items property of the CheckBoxList control to iterate through the list items and then use the Selected property of the ListItem object to find out whether the item has been selected. Answers A and B are incorrect because the SelectedIndex and SelectedItem properties return only the index of the first selected item and the first selected item, respectively. Answer C is incorrect because DataValueField is the data source that provides the item value and is used for populating the contents of CheckBoxList.

Question 3

You want to create a client-side event handler for the click event of a Button Web server control. The client-side event handler is written in JavaScript and is executed by the Web browser. The name of the Button control is btnSubmit, and the name of the JavaScript event handler is GlowButton(). How should you accomplish this in your Web form?

  1. <input id="btnSubmit" Type="Submit" Runat="Server"
        Value="Submit" onclick="GlowButton()"/>
  2. <input id="btnSubmit" Runat="Server"
        Value="Submit" onclick="GlowButton();"/>
  3. <asp:Button id="btnSubmit" Runat="Server"
          Value="Submit" onclick="GlowButton();"/>
  4. btnSubmit.Attributes.Add("onclick", "GlowButton();")

Answer D is correct. The preferred way to add client-side event handling code for Web server controls is via the Attributes property of the Web server controls. Answers A, B, and C are incorrect because these techniques interfere with the client-side event handling code generated by ASP.NET to perform automatic postback operations.

Question 4

You are using a DropDownList Web server control on a Web page that allows users to select a country name. Based on the user's selection of country, you want to display the drop-down list showing states in the selected country and several other country-specific fields. You don't want users to click a button to submit country information to the Web server. All your users have JavaScript-enabled browsers. You want to write a minimum of code; which of the following techniques would you use?

  1. Use an HTML server control instead of Web server controls.

  2. m B. Write client-side code in JavaScript to cause a postback when the user selects the country.

  3. m C. Set the AutoPostBack property to true.

  4. m D. Set the AutoEventWireup attribute to true.

Answer C is correct. You can specify a SelectedIndexChanged event to cause a form postback by setting the AutoPostBack property of the DropDownList Web server control to true. This technique automatically generates the required client-side code that causes the page postback when a user changes the selection. Answers A and B are incorrect because they require you to write additional code. Answer D is incorrect because the AutoEventWireup attribute is different from the AutoPostBack property and is used to specify whether ASP.NET will automatically call event handlers based on their names.

Question 5

You are creating a Web page that collects information about the various sports activities that interest your users. You want to display a sorted list of activities using a CheckBoxList, as shown in Figure 3.4. Which of the following ways should you choose to declare the CheckBoxList Web server control in your Web page?


Figure 3.4
How should you declare the CheckBoxList to display its items in the way shown here?

  1. <asp:CheckBoxList id="cblActivities" runat="server"
       RepeatColumns="2" RepeatDirection="Vertical"
       RepeatLayout="Table">
    ...
    </asp:CheckBoxList>
  2. <asp:CheckBoxList id="cblActivities" runat="server"
       RepeatColumns="2" RepeatDirection="Horizontal"
       RepeatLayout="Table">
    ...
    </asp:CheckBoxList>
  3. <asp:CheckBoxList id="cblActivities" runat="server"
       RepeatColumns="2" RepeatDirection="Vertical"
       RepeatLayout="Flow">
    ...
    </asp:CheckBoxList>
  4. <asp:CheckBoxList id="cblActivities" runat="server"
       RepeatColumns="2" RepeatDirection="Horizontal"
       RepeatLayout="Flow">
    ...
    </asp:CheckBoxList>

Answer A is correct. The given list is sorted, and you want to organize the elements vertically in a table of two columns. To achieve this, you should set the RepeatColumns property to 2, the RepeatDirection property to Vertical, and the RepeatLayout property to Table. Answers B and D are incorrect because the value of the RepeatDirection attribute should be set to Vertical rather than Horizontal. Answer C is incorrect because the value of the RepeatLayout attribute should be set to "Table" instead of "Flow".

Question 6

In a Web page, you are dynamically generating numerous Button controls. Each Button control is titled either Add or Update. You want to write a single event handler to handle events for all the Button controls. Which of the following options would you choose to ensure that you could take different actions when the Add or Update button is clicked?

  1. Write an event handler for the Click event. Use the event arguments passed to the event handler to determine whether an Add button or Update button was clicked, and take appropriate actions in the event handler.

  2. Write an event handler for the Command event. Use the event arguments passed to the event handler to determine whether an Add button or Update button was clicked, and take appropriate actions in the event handler.

  3. Set the CommandName property for each button to either Add or Update. Write an event handler for the Click event. Use the event arguments passed to the event handler to determine whether an Add button or Update button was clicked, and take appropriate actions in the event handler.

  4. Handle all the events in a page-level event handler such as the Load event.

Answer B is correct. The Command event is raised when the Button control is clicked. You can use the CommandEventArgs object to find the CommandName and CommandArguments associated with the button that initiated the event. Answers A and C are incorrect because the event arguments for the Click event do not give you enough information to determine the name of the button that was clicked. Answer D is incorrect because the Load event also does not have enough information available through its event arguments.

Question 7

You want to keep consistent formatting for all the Web forms in your application. To achieve this, you have created a CSS named styles.css and have linked it to all the Web pages. You have defined a style class named TextBoxStyle in styles.css to format text boxes onto the Web forms. Which of the following property settings would you use with the TextBox Web server control to use the TextBoxStyle style class?

  1. Class="TextBoxStyle"

  2. CssClass="TextBoxStyle"

  3. Class=".TextBoxStyle"

  4. CssClass=".TextBoxStyle"

Answer B is correct. When you want a Web server control to use a style class defined in a CSS file, you use the CssClass property of the Web server control. Answers A and C are incorrect because the Class property is used only with HTML server controls and not with Web server controls. Answer D is incorrect because, although the style itself might be defined as .TextBoxStyle, in the CSS file, you only need to specify the name (for example, TextBoxStyle) with the CssClass property.

Question 8

You are a Web developer working for a state-run agency and are creating a Web site for senior welfare programs. To register with the program, seniors must enter both their name and date of birth. The Web site should register a user only if her age is 65 years or more. You want to minimize the amount of validation code. How would you set up validation in the Web form to achieve this objective? (Select all that apply.)

  1. Use RequiredFieldValidator with the name.

  2. Use RequiredFieldValidator with the date of birth.

  3. Use CompareValidator with the date of birth.

  4. Use RangeValidator with the date of birth.

  5. Use CustomValidator with the date of birth.

Answers A, B, and C are correct. It is required that both the name and the date of birth be entered, so you must use the RequiredFieldValidator for both the fields. In addition to this, you need to compare the date of birth entered by the user with the current date to check whether she is 65 years or older. This can be easily done using the CompareValidator control by programmatically setting its ValueToCompare property. Answer D is incorrect because no fixed range has been specified for the age. Answer E is incorrect because it requires you to write additional validation code.

Question 9

You are developing a scheduling application for your company's intranet. You are using a Calendar control to enable easy and correct selection of dates. You want to mark holidays on the calendar so that users are aware of them while creating a schedule. For example, January 1 should be marked as New Year's Day. You want to display the description of the holiday in the same cell that displays the date. Which of the following calendar events would you use to achieve this?

  1. DayRender

  2. SelectionChanged

  3. VisibleMonthChanged

  4. Load

Answer A is correct. The DayRender event is raised when the Calendar control is rendered. The DayRender event is therefore the preferred place for writing additional messages along with a day. Answers B and C are incorrect because these events are fired on a user action only after the Calendar control has been displayed. Answer D is incorrect because the Load event is fired prior to the actual rendering of the control.

Question 10

You are designing a Web site that allows users to file their taxes online. Users log on to the Web site using their tax identification number and a personal identification number. You want to ensure that users do not include spaces with the tax identification number. You want to achieve this by writing the minimum amount of code. Which of the following validation controls would you choose?

  1. RequiredFieldValidator

  2. RangeValidator

  3. RegularExpressionValidator

  4. CustomValidator

Answer C is correct. The RegularExpressionValidator control is the best choice for performing validations that require you to match the control's value against a specific pattern. Answer A is incorrect because the RequiredFieldValidator only ensures whether a value is entered. Answer B is incorrect because no specific range of values has been specified. Answer D is incorrect because the CustomValidator control requires you to write additional code.

Need to Know More?

Kalani, Amit, et al. ASP.NET 1.0 with C# Namespace Reference. Hoboken, NJ: Wrox, 2002.

Liberty, Jesse and Dan Hurwitz. Programming ASP.NET. Sebastopol, CA: O'Reilly, 2002.

See the ASP.NET Server Controls Overview at http://support.microsoft.com?scid=kb;en-us;Q306459.

Visit the Microsoft Online Seminars on ASP.NET at http://www.microsoft.com/Seminar/MMCFeed/MMCDisplay.asp?Product=103362.

See The .NET Show: ASP.NET at http://www.msdn.com/theshow/Episode009.

See the MSDN TV: Client-Side Script in ASP.NET at http://www.msdn.com/msdntv/episode.aspx?xml=episodes/en/20030311ASPNETJC/manifest.xml.

See the MSDN ASP.NET Seminars at http://www.msdn.com/seminar/mmcfeed/mmcdisplayfeed.asp?Product=103362.

Read MSDN Magazine's "The ASP Column" at http://www.msdn.com/msdnmag/find/default.aspx?phrase=TheASPColumn.

Read about the .NET Framework Regular Expressions at http://www.msdn.com/library/en-us/cpguide/html/cpconcomregularexpressions.asp.

800 East 96th Street, Indianapolis, Indiana 46240

sale-70-410-exam    | Exam-200-125-pdf    | we-sale-70-410-exam    | hot-sale-70-410-exam    | Latest-exam-700-603-Dumps    | Dumps-98-363-exams-date    | Certs-200-125-date    | Dumps-300-075-exams-date    | hot-sale-book-C8010-726-book    | Hot-Sale-200-310-Exam    | Exam-Description-200-310-dumps?    | hot-sale-book-200-125-book    | Latest-Updated-300-209-Exam    | Dumps-210-260-exams-date    | Download-200-125-Exam-PDF    | Exam-Description-300-101-dumps    | Certs-300-101-date    | Hot-Sale-300-075-Exam    | Latest-exam-200-125-Dumps    | Exam-Description-200-125-dumps    | Latest-Updated-300-075-Exam    | hot-sale-book-210-260-book    | Dumps-200-901-exams-date    | Certs-200-901-date    | Latest-exam-1Z0-062-Dumps    | Hot-Sale-1Z0-062-Exam    | Certs-CSSLP-date    | 100%-Pass-70-383-Exams    | Latest-JN0-360-real-exam-questions    | 100%-Pass-4A0-100-Real-Exam-Questions    | Dumps-300-135-exams-date    | Passed-200-105-Tech-Exams    | Latest-Updated-200-310-Exam    | Download-300-070-Exam-PDF    | Hot-Sale-JN0-360-Exam    | 100%-Pass-JN0-360-Exams    | 100%-Pass-JN0-360-Real-Exam-Questions    | Dumps-JN0-360-exams-date    | Exam-Description-1Z0-876-dumps    | Latest-exam-1Z0-876-Dumps    | Dumps-HPE0-Y53-exams-date    | 2017-Latest-HPE0-Y53-Exam    | 100%-Pass-HPE0-Y53-Real-Exam-Questions    | Pass-4A0-100-Exam    | Latest-4A0-100-Questions    | Dumps-98-365-exams-date    | 2017-Latest-98-365-Exam    | 100%-Pass-VCS-254-Exams    | 2017-Latest-VCS-273-Exam    | Dumps-200-355-exams-date    | 2017-Latest-300-320-Exam    | Pass-300-101-Exam    | 100%-Pass-300-115-Exams    |
http://www.portvapes.co.uk/    | http://www.portvapes.co.uk/    |