-->

22 December 2019

Asp.Net TextBox Control

  Asp.Net CS By Example       22 December 2019

  The TextBox Control :
     In this post, we are leaning about ASP.NET TextBox Control.The TextBox control is used to accepting data from user. The TextBox control to display three different types of input fields depending on the value of its TextMode property.
The TextMode property accepts the following three values:
S.N. Properties Description
1) SingleLine Display a single-line input box.
2) MultiLine Display a multiline input box.
3) Password Display a single-line input box in which the text (input data display as '*') is hidden.


Syntax:
<asp:Textbox ID="txtUserID" runat="server"  />



We can use the belows properties to control the displaying characteristics of the TextBox control (but this is not complete list):
S.N. Property Description
1) ID Set the uniqe value to control to access in code-behind code.
2) Text This use for set or get value from or to textbox control.
3) AccessKey This property used to specify a key that navigates to the TextBox control.
4) AutoCompleteType Used to associate an AutoComplete class for TextBox control.
5) AutoPostBack Enables we to post the form containing the TextBox back to the server automatically when the contents of the TextBox is changed.
6) Columns Used to set how many column of text must be display.
7) Enabled This used to enable or disable the Textbox control.
8) MaxLength Used to set the maximum length of data that a user can enter in a text box. (This does not work when TextMode is set to Multiline.)
9) ReadOnly Used to prevent users from changing the text from a text box.
10) Rows Enables we to specify the number of rows to display.
11) TabIndex Used to set the tab order of the text box.
12) Wrap Used to set whether text word-wraps when the TextMode is set to Multiline.

The TextBox control also supports the following method:
S.N. Method Description
1) Focus Used to set the initial form focus on it.

The TextBox control supports the following event:
SN. Event Description
1) TextChanged Raised on the server when the contents of the text box are changed.

  When the AutoPostBack property has the value True, the form containing the TextBox is
automatically posted back to the server when the contents of the TextBox changes.

Code: TextBoxControlDemo.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TextBoxControlDemo.aspx.cs" 
    Inherits="LearnAsp.Net.Control.TextControl.TextBoxControlDemo" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
        html {
            background-color: #defbfa;
            font: 14px Georgia,Serif;      
        }

        .content {
            background-color: #c8daa6;
            width: 600px;
            margin: auto;
            padding: 20px;
            border-radius: 23px;
        }

        .addressLabel {
            float: left;
            width: 100px;
            padding: 5px;
            text-align: left;
        }

        .ColonLabel {
            float:  left;
            width: 20px;
            padding: 5px;
            text-align: left;
        }

        .addressField {
            float: left;
            padding: 5px;
        }

        .clear {
            clear: both;
        }

        .Title {
            text-align: center;
            font-size: 23px;
            margin-top: 50px;
            
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div class="content">
            <fieldset style="border-radius: 23px;">
                <legend  class="Title" >
                    <asp:Literal ID="ltlTitle"   Text="{ TextBox Control Demo }" runat="server" />
                </legend>
                <div class="addressLabel">
                    <asp:Label ID="lblStreet"  Text="TextBox Field" AssociatedControlID="txtUserId" runat="server" />
                </div>
                <div class="ColonLabel">
                    <asp:Label ID="Label1" Text=":" runat="server" />
                </div>
                <div class="addressField">
                    <asp:TextBox ID="txtUserId" runat="server" />
                    <asp:RequiredFieldValidator ID="reqStreet" Text="(required)" ControlToValidate="txtUserId"
                        runat="server" />
                </div>
                <br class="clear" />
                <div class="addressLabel">
                    <asp:Label ID="lblCity" Text="Password Feild" AssociatedControlID="txtPassword" runat="server" />
                </div>
                <div class="ColonLabel">
                    <asp:Label ID="Label2" Text=":" runat="server" />
                </div>
                <div class="addressField">
                    <asp:TextBox ID="txtPassword" TextMode="Password" runat="server" />
                    <asp:RequiredFieldValidator ID="reqCity" Text="(required)" ControlToValidate="txtPassword"
                        runat="server" />
                </div>
                <br class="clear" />
                <div class="addressLabel">
                    <asp:Label ID="lblState" Text="MultiLine Field" AssociatedControlID="txtAddress" runat="server" />
                </div>
                <div class="ColonLabel">
                    <asp:Label ID="Label3" Text=":" runat="server" />
                </div>
                <div  class="addressField">
                    <asp:TextBox ID="txtAddress" TextMode="MultiLine" Rows="3" Columns="35" runat="server" />
                    <asp:RequiredFieldValidator ID="reqState" Text="(required)" ControlToValidate="txtAddress"
                        runat="server" />
                </div>
                <br class="clear" />

            </fieldset>
        </div>
    </form>
</body>
</html>

Output:

logoblog

Thanks for reading Asp.Net TextBox Control

Previous
« Prev Post

No comments:

Post a Comment

Please do not enter any spam link in the comment box.