asp.net.ph

Skip Navigation LinksHome > Getting Started > ASP.NET Syntax > ASP.NET Syntax for HTML Controls > HtmlInputText

HtmlInputText Control Syntax

HtmlInputText Class   Input Text Element


Creates a single-line text entry control.

Declarative Syntax

For information on the individual members of this class, see HtmlInputText in the class library.

Syntax Notes

  • This control does not require a closing tag.

Working with HtmlInputText

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.

Verifying TextBox Entries Against Values Stored on a Page

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.

Verifying TextBox Entries Against Values Stored on the Page
Run Sample | View Source
  1. 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>
  2. 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>

Verifying TextBox Entries Against Values Stored in a Database

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.

Verifying TextBox Entries Against Values Stored in a Database
Run Sample | View Source

Text boxes can be used in combination with validation controls to verify that users are entering the correct information.

See Also

HtmlInputText Class   Input Text Element   Web Forms Events and Handlers



© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note