TextArea Length ???

S

Samir Patel

Hi
I am using Textarea type.I want to set maximum length to the textarea.
I am using following code for the same,but it is not working,

<textarea name="txtDescription" cols=10 rows=3 axlength=50></textarea>
<asp:TextBox Font-Names="verdana" Runat="server" ID="tforumtext"
TextMode="MultiLine" Height="100" Width="300" Font-Size="10"
MaxLength="100">
</asp:TextBox>

But it is not working,it
Help me in the same

Samir (S.E INDIA).
 
M

Mohamed El Ashmawy

Hello Samir ,
The textarea doesn't have a maximum length property, but you can achieve
what you want through a simple vbscript code.
First you need to create a VBscript method that would check on the
maxlength and disallow any additions if the maxlength is passed.Here is a
sample:

<script language="vbscript">

dim maxlength
maxlength =5
sub EnsureMaxLength()
if (len(document.Form1.mytextarea.innerText) >=(maxlength+1))then
document.Form1.mytextarea.innerText =
left(document.Form1.mytextarea.innerText,maxlength)
end if
end sub

</script>

You need also to call this method in the onpropertychange event of the
textarea

Regards
Mohamed El Ashmawy
MEA Developer Support Center
ITWorx on behalf of Microsoft EMEA GTSC
 
S

Scott Mitchell [MVP]

Samir, this post by Peter Blum shows how to use a
RegularExpressionValidator to ensure that a form field's length is
within a certain bounds:
http://tinyurl.com/7xyht

I have created a custom validator control that you can use to ensure
that a TextBox (even a multi-lined one) is less than a certain value.
Details at:
http://aspnet.4guysfromrolla.com/articles/112404-1.aspx

Happy Programming!


--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com

* When you think ASP.NET, think 4GuysFromRolla.com!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,800
Messages
2,569,657
Members
45,416
Latest member
MyraTrotte
Top