Home > Getting Started > ASP.NET Syntax > ASP.NET Syntax for HTML Controls > HtmlInputText
HtmlInputText Class Input Text Element
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 samples illustrate 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 Web Forms page, declare an HtmlForm control to contain two HtmlInputText controls, two HtmlInputButton controls, and a <p runat="server"
>
control.
<form runat="server">
<p>Login: <input id="logIn" runat="server">
<p>Password: <input type=password id="passWord" runat="server">
<p><input type=submit value="Enter" runat="server"
onServerClick="submitHandler">
<input type=reset runat="server">
<p id="msg" runat="server" />
</form>
- In the <
head
> of the Web Forms page, define the event handler for the submit button.
<script language="C#" runat="server">
void submitHandler ( object Source, EventArgs e ) {
if ( passWord.Value == "asp.net" ) msg.InnerHtml = "Password is correct";
else msg.InnerHtml = "That password is not correct";
}
</script>
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 Input Text Element Web Forms Events and Handlers