Onlineatoz.net | ToolBox HTML Control HTMLText

ToolBox HTML Control HTMLText

HTML Text Web Server Control

In ASP.NET environment,This article describes you how to work with HTML Text Control.In HTML environment, Text is an object that represents a Textbox in an HTML form. The Textbox control in a HTML form contains all instance of an <input type="text"> tag. Likewise, There are one more kind of textbox is <input type="password"> and <input type="reset">

There are several functions available to access the HTML Text.some of its funtions are as follows,

  • document.getElementById()
  • document.getElementByName()
Text Objects Properties
  • id -Sets or returns the id of a Text
  • form -Returns a reference to the form that contains the Text
  • accessKey -Sets or returns the keyboard key to access a Text
  • alt -Sets or returns an alternate text to display if a browser does not support Texts
  • disabled -Sets or returns whether or not a Text should be disabled
  • tabIndex -Sets or returns the tab order for a Text
  • name -Sets or returns the name of a Text
  • type -Returns the type of form element a Text is
  • maxLength - Sets or returns the maximum number of characters in a text field
  • readOnly -Sets or returns whether or not a text field should be read-only
  • value -Sets or returns the text that is displayed on the Text
  • title -Sets or returns an element's advisory title
  • lang -Sets or returns the language code for an element
  • dir -Sets or returns the direction of text
  • className -Sets or returns the class attribute of an element
Text Objects Methods
  • blur() -Performs focus when leave from the control
  • click() -Simulates a mouse-click on a Text
  • focus() -Performs focus when enter into the control

The following code snippets explains you the HTML Text in the web form.

in .aspx.cs page,

protected void AddButton_Click(Object sender, EventArgs e)
      {
         int Answer;
         Answer = Convert.ToInt32(txt1.Value) + Convert.ToInt32(txt2.Value);
         AnswerMessage.InnerHtml = Answer.ToString();
      }
        

in .aspx page,

 <form id="Form2" runat="server">
      <h3>Example </h3>
      <table>         
         <tr align="center">
            <td>
               <input ID="txt1"
                     Type="Text"
                      Size="2"
                      MaxLength="3"
                      Value="1"
                     runat="server"/>
            </td>
            <td>
               + 
            </td>
            <td>
               <input ID="txt2"
                     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="req1"
                    ControlToValidate="txt1"
                    ErrorMessage="Please enter a value.<br>"
                    Display="Dynamic"
                    runat="server"/>

               <asp:CompareValidator
                    ID="comp1"
                    ControlToValidate="txt1"
                    Operator="LessThan"
                    Type="Integer"
                    ValueToCompare="100"
                    ErrorMessage="Please enter an integer less than 100.<br>"
                    Display="Dynamic"
                    runat="server"/>
               <asp:CompareValidator
                    ID="comp2"
                    ControlToValidate="txt1"
                    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="req2"
                    ControlToValidate="txt2"
                    ErrorMessage="Please enter a value.<br>"
                    Display="Dynamic"
                    runat="server"/>

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

               <asp:CompareValidator
                    ID="comp4"
                    ControlToValidate="txt2"
                    Operator="GreaterThan"
                    Type="Integer"
                    ValueToCompare="0"
                    ErrorMessage="Please enter an integer greater than 0.<br>"
                    Display="Dynamic"
                    runat="server"/>
            </td>
            <td>
                 
            </td>
         </tr>
         <tr align="center">
            <td colspan="4">
               <input id="Submit1" Type="Submit"
                      Name="AddButton"
                      Value="Add"
                      OnServerClick="AddButton_Click"
                      runat="server"/>
                  
               <input id="Reset1" Type="Reset"
                      Name="AddButton"
                      Value="Reset"
                      runat="server"/>
            </td>
            <td>
                
            </td>
         </tr>
      </table>
   </form>
        
 
Related Links


Posted by: Admin
Posted on: 9/11/2011 at 8:39 PM
Categories: Asp.net
Actions: E-mail | Kick it! | DZone it! | del.icio.us
Post Information: Permalink | Comments (0) | Post RSSRSS comment feed