Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

HtmlInputText Class

Allows programmatic access to the HTML <input type= text> and <input type= password> elements on the server.

Namespace: System.Web.UI.HtmlControls
Assembly: System.Web (in system.web.dll)

[ValidationPropertyAttribute("Value")] 
public class HtmlInputText : HtmlInputControl, IPostBackDataHandler
/** @attribute ValidationPropertyAttribute("Value") */ 
public class HtmlInputText extends HtmlInputControl implements IPostBackDataHandler
ValidationPropertyAttribute("Value") 
public class HtmlInputText extends HtmlInputControl implements IPostBackDataHandler

Use the HtmlInputText control to create a single-line text box that allows the user to enter text or a password. The MaxLength property specifies the maximum number of characters that can be entered in the text box. The Size property allows you to specify the width of the text box. To determine the value entered by the user into text box, use the Value property. The HtmlInputText control provides a ServerChange event that is raised when the Value property changes values between posts to the server. This allows you to create an event handler that performs a custom set of instructions each time the event is raised.

NoteNote

The HtmlInputText control does not provide a built-in way to post back to the server. You must provide another control on the Web page that supports posting to the server, such as an HtmlButton control, to send the value of the control back to the server.

To create a multi-line text box, use the HtmlTextArea control.

For a list of initial property values for an instance of HtmlInputText, see the HtmlInputText constructor.

The following code example demonstrates how to use the HtmlInputText control to get user input.

<%@ Page Language="C#" AutoEventWireup="True" %>

<html> 

<head>

   <script runat="server">

      protected void AddButton_Click(Object sender, EventArgs e)
      {
         int Answer;

         Answer = Convert.ToInt32(Value1.Value) + Convert.ToInt32(Value2.Value);

         AnswerMessage.InnerHtml = Answer.ToString();

      }

   </script>

</head>

<body>

   <form runat="server">

      <h3> HtmlInputText Example </h3>

      <table>

         <tr>

            <td colspan="5">

               Enter integer values into the text boxes. <br>
               Click the Add button to add the two values. <br>
               Click the Reset button to reset the text boxes.

            </td>

         </tr>

         <tr>

            <td colspan="5">

               &nbsp;

            </td>

         </tr>

         <tr align="center">

            <td>

               <input ID="Value1"
                      Type="Text"
                      Size="2"
                      MaxLength="3"
                      Value="1"
                      runat="server"/>

            </td>

            <td>

               + 

            </td>

            <td>

               <input ID="Value2"
                      Type="Text"
                      Size="2"
                      MaxLength="3"
                      Value="1"
                      runat="server"/>

            </td>

            <td>

               =

            </td>

            <td>
               
               <span ID="AnswerMessage"
                     runat="server"/>

            </td>

         </tr>

         <tr>

            <td colspan="2">

               <asp:RequiredFieldValidator
                    ID="Value1RequiredValidator"
                    ControlToValidate="Value1"
                    ErrorMessage="Please enter a value.<br>"
                    Display="Dynamic"
                    runat="server"/>

               <asp:CompareValidator
                    ID="Value1MinCompareValidator"
                    ControlToValidate="Value1"
                    Operator="LessThan"
                    Type="Integer"
                    ValueToCompare="100"
                    ErrorMessage="Please enter an integer less than 100.<br>"
                    Display="Dynamic"
                    runat="server"/>

               <asp:CompareValidator
                    ID="Value1MaxCompareValidator"
                    ControlToValidate="Value1"
                    Operator="GreaterThan"
                    Type="Integer"
                    ValueToCompare="0"
                    ErrorMessage="Please enter an integer greater than 0.<br>"
                    Display="Dynamic"
                    runat="server"/>

            </td>

            <td colspan="2">

               <asp:RequiredFieldValidator
                    ID="Value2RequiredValidator"
                    ControlToValidate="Value2"
                    ErrorMessage="Please enter a value.<br>"
                    Display="Dynamic"
                    runat="server"/>

               <asp:CompareValidator
                    ID="Value2MinCompareValidator"
                    ControlToValidate="Value2"
                    Operator="LessThan"
                    Type="Integer"
                    ValueToCompare="100"
                    ErrorMessage="Please enter an integer less than 100.<br>"
                    Display="Dynamic"
                    runat="server"/>

               <asp:CompareValidator
                    ID="Value2MaxCompareValidator"
                    ControlToValidate="Value2"
                    Operator="GreaterThan"
                    Type="Integer"
                    ValueToCompare="0"
                    ErrorMessage="Please enter an integer greater than 0.<br>"
                    Display="Dynamic"
                    runat="server"/>

            </td>

            <td>

               &nbsp
 
            </td>

         </tr>

         <tr align="center">

            <td colspan="4">

               <input Type="Submit"
                      Name="AddButton"
                      Value="Add"
                      OnServerClick="AddButton_Click"
                      runat="server"/>

               &nbsp;&nbsp;&nbsp;

               <input Type="Reset"
                      Name="AddButton"
                      Value="Reset"
                      runat="server"/>

            </td>

            <td>

               &nbsp;

            </td>

         </tr>

      </table>

   </form>

</body>
</html>

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.