Home > Getting Started > ASP.NET Syntax > ASP.NET Syntax for HTML Controls > HtmlInputText
ASP.NET Syntax ASP.NET Syntax for HTML Controls
Creates a single-line text entry control.
Declarative Syntax
<input type = "text | password" id="accessID" runat="server"
maxlength = "maxnumberofcharacters"
size = "widthoftextbox"
value="defaulttextboxcontents"
>
For information on the individual members of this class, see HtmlInputText in the class library.
- This control does not require a closing tag.
The HtmlInputText control is a single-line input control that accepts text entries. HtmlInputText supports two behaviors. If Type is Text
( the default ), the control acts as a standard textbox. If Type is Password
, the user’s input is masked by the asterisk ( * ) character to prevent it from being seen.
The HtmlInputText control allows to run server code against the HTML <input type=text
> and <input type=password
> elements. You can dynamically retrieve or assign values to the control’s MaxLength, Size, and Value properties.
This control is typically used in conjunction with form submission controls, such as HtmlInputButton, HtmlInputImage, or HtmlButton, to send and process user input on the server.
The following sample illustrates use of the HtmlInputText control in both Text
and Password
modes.
The following example shows a simple authentication scenario, wherein the value entered in a text box is compared to a pre-set value defined in the Web Forms page.
- In the BODY of the page, define the HtmlForm to contain two HtmlInputText controls, an HtmlInputButton to submit the form, and a span control to render the message returned by the handler.
<body>
<form runat="server">
<table cellpadding=5>
<tr>
<td>Login: </td>
<td><input id="Name" runat="server"></td></tr>
<tr>
<td>Password: </td>
<td><input id="Password" type=password runat="server"></td></tr>
<tr>
<td colspan=2 align = "center"><input type=submit
value="Enter"
onServerClick = "submitHandler"
runat="server"></td></tr>
</table>
<p><span id="Message" runat="server" />
</form>
</body>
- In the <
head
> of the Web Forms page, define the handler for the click event of the button.
<head>
<script language="C#" runat="server">
void submitHandler ( object Source, EventArgs e ) {
if ( Password.Value == "ASP.NET" )
Message.InnerHtml = "Password is correct";
else
Message.InnerHtml = "That password is not correct";
}
</script>
</head>
A more advanced scenario would be to verify the entered text against values stored in a database. In this exercise, enter me@me.com
for the user email and ado.net
for the password.
Text boxes can be used in combination with validation controls to verify that users are entering the correct information.
HtmlInputText Class HtmlInputButton Control HtmlInputControl Class Web Forms Events and Handlers