WorkflowGen.com | Knowledge Base | Documentation | Downloads | Support | RSS

« When a web form loads, how can I make the cursor start in a specific text box? | Main | How do I change labels in an existing language? »

How can I set the maximum length of a multi-line text box in a web form?

Posted on Sunday, February 10, 2008 at 16:24 by Registered CommenterWFG Team in | Comments1 Comment

Restricting the length of text on a Multi line textbox is not supported by the standard ASP.NET Web control. This can be done by adding the following Javascript function in your ASPX page.

1. Add a javascript:

At the top of your ASPX page you will see the following tag </ head > . A dd the following code under this tag:

<script language="javascript" type="text/javascript">function Count(text,long)

{

    var maxlength = new Number(long); // Change number to your max length.

    if (text.value.length > maxlength){

        text.value = text.value.substring(0,maxlength);

        alert(
" Only " + long + " chars");

    }

}

</script>

2. Change your text controls on your ASPX page

On every multi-line text box where you would like to control the length, add the following code to the asp text box control.

onKeyUp="Count(this,50)" onChange="Count(this,50)"

Your original text control before adding this code:

<asp:TextBox ID="TESTDATA" runat="server" TextMode="MultiLine"></asp:TextBox>

After adding the code:

<asp:TextBox ID="TextBox1" runat="server" onKeyUp="Count(this,50)" onChange="Count(this,50)" TextMode="MultiLine"></asp:TextBox>

Reader Comments (1)

When i am using a remote launch to invoke a web service i am getting an error "This process cannot be launched by an external application" what r the causes of the error??
May 14, 2008 | Registered Commentervista
Member Account Required
You must have a member account on this website in order to post comments. Log in to your account to enable posting.