programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Website by URL, How to Play YouTube Videos in by using Jquery , Jquery Change div background on mouseover in , JQuery UI Datepicker (Calendar) etc.

Sunday, March 29, 2015

Set MaxLength property of multiline textbox

How to set MaxLength property of multiline textbox:

We all apprehend that we are able to set the utmost allowed characters in traditional textbox by setting its MaxLength property to desired range of characters. however same doesn’t work if the TextMode property of textbox is ready to Multiline.

When a Textbox is in SingleLine mode that is default TextMode , it gets rendered as AN input kind textbox  and after we set its TextMode property  to MultiLine, it gets rendered as a textarea. As we know, MaxLength property works just for input kind and not for textarea. however There square measure multiple ways in which to handle this victimization javascript,  jquery or regular expression. however I got the straightforward answer to handle this while not victimization jquery or regularexpression.

HTML Source for How to set MaxLength property of

<html xmlns="">
<head runat="server">
    <title> Set Max Length of multiline textbox </title>
    <form id="form1" runat="server">
       <fieldset style="width:300px;">
           <legend>Set max length of multiline textbox</legend>
           <asp:TextBox ID="txtComments" runat="server" Width="300px" TextMode="MultiLine"MaxLength="60" placeholder="Max allowed:60 characters"></asp:TextBox>

Asp.Net C# code to set max length of multiline textbox:

protected void Page_Load(object sender, EventArgs e)
        if (!Page.IsPostBack)
            txtComments.Attributes.Add("maxlength", txtComments.MaxLength.ToString());

No comments:

Post a Comment