Adding an ASP Dot Net control

Learning Resources

Adding an ASP Dot Net control

In this part of the walkthrough, you will add a Button, a TextBox, and a Label control to the page and write code to handle the Click event for the Button control.

You will now add server controls to the page. Server controls, which include buttons, labels, text boxes, and other familiar controls, provide typical form-processing capabilities for your ASP.NET Web pages. However, you can program the controls with code that runs on the server, not the client.

To add controls to the page

  1. Click the Design tab to switch to Design view.

  2. Put the insertion point at the end of the Welcome to Visual Web Developer text and press ENTER five or more times to make some room in the div element box.

  3. In the Toolbox, expand the Standard group.

  4. Drag a TextBox control onto the page and position it in the middle of the div element box that has Welcome to Visual Web Developer in the first line.

  5. Drag a Button control onto the page and position it to the right of the TextBox control.

  6. Drag a Label control onto the page and position it on a separate line below the Button control.

  7. Put the insertion point above the TextBox control, and then type Enter your name:.

    This static HTML text is the caption for the TextBox control. You can mix static HTML and server controls on the same page. The following screen shot shows how the three controls appear in Design view.

    Controls in Design View

    Three controls in Design view

Setting Control Properties

Visual Web Developer offers you various ways to set the properties of controls on the page. In this part of the walkthrough, you will set properties in both Design view and Source view.

To set control properties

  1. Select the Button control, and then in the Properties window, set Text to Display Name, as shown in the following screen shot.

    Changed Button control text

    Set Button text
  2. Switch to Source view.

    Source view displays the HTML for the page, including the elements that Visual Web Developer has created for the server controls. Controls are declared using HTML-like syntax, except that the tags use the prefix asp: and include the attribute runat="server".

    Control properties are declared as attributes. For example, when you set the Text property for the Button control, in step 1, you were actually setting the Text attribute in the control's markup.

    Note that all the controls are inside a

    element, which also has the attribute runat="server". The runat="server" attribute and the asp: prefix for control tags mark the controls so that they are processed by ASP.NET on the server when the page runs. Code outside of and