Input Controls in ASP.NET
Introduction
and Demonstration
Input controls let the user
enter text 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 as follows:
<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 using the Text property, but can be set using the attributes collection as shown in the preceding code snippet (though this is not recommended, since it results in the password being rendered to the client in plain text).
Index.aspx
Page:
<%@
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 = "Multiline
TextBox can hold many lines of text"
End Sub
</script>
</head>
<body>
<h1>Input Control Example</h1>
<form runat="server">
<table border="1"
cellpadding="5" cellspacing="0">
<tr>
<td>
Single Line TextBox:
</td>
<td>
<asp:textbox
id="SingleText"
text="Single Line
TextBox"
runat="server"
/>
</td>
</tr>
<tr>
<td>
Password TextBox:
</td>
<td>
<asp:textbox
id="PasswordText"
text="Password"
textmode="Password"
runat="server"
/>
</td>
</tr>
<tr>
<td>
Multiline TextBox:
</td>
<td>
<asp:textbox
id="MultiText"
text="Multiline
TextBox"
textmode="Multiline"
runat="server"
/>
</td>
</tr>
</table>
</form>
</body>
</html>
Comments
Post a Comment