TextBox TextMode in ASP.Net
In this asp.net tutorial we will discuss about TextBox control TextMode property in detail.
We can use textbox control as a single line text input or as a multi line text input or as a password text input control. A by default textbox control is a single line textbox, we can change programmatically textbox mode from single line to multi line or password by writting c# code.
In ASP.Net 4.5 Microsoft has added new textbox textmode feature. In previous old ASP.Net version TextBox control had only three properties for TextMode.
- SingleLine
- MultiLine
- Password
Microsoft added more features with version ASP.Net 4.5 for TextBox TextMode property.
TextMode | Description |
---|---|
SingleLine | It is used to display single line textbox. for single line value. |
MultiLine | It is used to display multi line textbox. textarea for address field. |
Password | It is used to display password textbox. shows password * character. |
Color | It is used to set color picker. |
Date | It is used for date entries, enter only dates. |
DateTime | It is used for datetime entries. |
DateTimeLocal | It is used for datetime entries with local time zome. |
It is used for email address entries. | |
Month | It is used for month and year entries. |
Number | It is used for numbers entries. allow only numeric values. |
Range | It is used for range between two numbers. |
Search | It is used for search text field. |
Phone | It is used for phone number entries. |
Time | It is used for time entries. |
Url | It is used for website url entries. |
Week | It is used for week and year entries. |
<asp:TextBox ID="TextBox1" runat="server" TextMode="SingleLine" ></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine" ></asp:TextBox> <asp:TextBox ID="TextBox3" runat="server" TextMode="Password" ></asp:TextBox>
SingleLine, MultiLine and Password TextMode Example
In this asp.net TextBox TextMode example we will change TextMode property programmatically by using c#. Here we have taken three button control one for SingleLine, second for MultiLine and Password mode.
C# code for above example
protected void btnsingleline_Click(object sender, EventArgs e) { TextBox1.TextMode = TextBoxMode.SingleLine; Label1.Text = "Single Line TextBox"; } protected void btnmultiline_Click(object sender, EventArgs e) { TextBox1.TextMode = TextBoxMode.MultiLine; Label1.Text = "Multi Line TextBox"; } protected void btnpassword_Click(object sender, EventArgs e) { TextBox1.TextMode = TextBoxMode.Password; Label1.Text = "Password TextBox"; }
Example of TextBox TextMode Properties
Now, we use all TextMode properties of TextBox in this asp.net example as show in above list.
Below example shows the TextMode property Color, Email, Number, Url, Search and Range.
Html code for .aspx page are :
<asp:TextBox ID="txtcolor" runat="server" TextMode="Color" ></asp:TextBox> <asp:TextBox ID="txtemail" runat="server" TextMode="Email" ></asp:TextBox> <asp:TextBox ID="txtnumber" runat="server" TextMode="Number" ></asp:TextBox> <asp:TextBox ID="txturl" runat="server" TextMode="Url" ></asp:TextBox> <asp:TextBox ID="txtsearch" runat="server" TextMode="Search" ></asp:TextBox> <asp:TextBox ID="txtrange" runat="server" TextMode="Range" ></asp:TextBox>
C# code above example
Here, we have two button one for Color property and other for Range property.
protected void btncolor_Click(object sender, EventArgs e) { Label1.Text = "Code = " + txtcolor.Text; Label2.Attributes.Add("style", "color:" + txtcolor.Text + ""); } protected void btnrange_Click(object sender, EventArgs e) { lblrange.Text = txtrange.Text; }
Example : Date, DateTime, DateTimeLocal, Month, Time, Week
<asp:TextBox ID="txtdate" runat="server" TextMode="Date" ></asp:TextBox> <asp:TextBox ID="txtdatetime" runat="server" TextMode="DateTime" ></asp:TextBox> <asp:TextBox ID="txtdatetimelocal" runat="server" TextMode="DateTimeLocal" ></asp:TextBox> <asp:TextBox ID="txtmonth" runat="server" TextMode="Month" ></asp:TextBox> <asp:TextBox ID="txttime" runat="server" TextMode="Time" ></asp:TextBox> <asp:TextBox ID="txtweek" runat="server" TextMode="Week" ></asp:TextBox>
Thank you Meera Academy….
I have submitted my Msc.IT assignment with help of these tutorials.
It’s very easy to understand.