O'Reilly logo

ASP.NET in a Nutshell by Matthew MacDonald, G. Andrew Duthie

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Types of Web Controls

Web controls fall into five categories: display, input, selection, validation, and special purpose.

Input Controls

Input controls let the user enter data into the application. ASP.NET supports only one input web control: the TextBox. The TextBox behaves like a single-line or multiline edit control, depending on the value of its TextMode property. Its simplified syntax is:

<asp:textbox id="SingleText" 
   text="Single Line TextBox" 
   runat="server" />
  
<asp:textbox id="PasswordText" 
   text="Password" 
   textmode="Password" 
   runat="server" />
  
<asp:textbox id="MultiText" 
   text="Multiline TextBox" 
   textmode="Multiline" 
   runat="server" />

The TextBox control can then be accessed programmatically with a code fragment like:

SingleText.Text = "Hello ASP.NET"
PasswordText.Attributes("Value") = "New Password"
MultiText.Text = "Multiline TextBox can hold many lines of text"

Note that the text of a TextBox control using the Password text mode cannot be set directly.

The appearance of input controls when rendered to the browser is shown in Figure 5-1. The code used to generate this figure is shown in Example 5-5.

Rendering of input controls

Figure 5-1. Rendering of input controls

Example 5-5. InputControls.aspx

<%@ Page Language="vb" %> <html> <head> <title>Input Control Example</title> <script runat="server"> Sub Page_Load( ) SingleText.Text = "Hello ASP.NET" PasswordText.Attributes("Value") = "New Password" MultiText.Text ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required