asp.net.ph

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

HtmlInputText Control Syntax

ASP.NET Syntax   ASP.NET Syntax for HTML Controls


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 ( Text and Password )

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.


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 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>
  2. 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>

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   HtmlInputButton Control   HtmlInputControl Class   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