Groups | Blog | Home
all groups > asp.net webcontrols > november 2004 >

asp.net webcontrols : TextArea Length ???


mohamed.elashmawy NO[at]SPAM egdsc.microsoft.com (
11/20/2004 10:06:35 AM
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
Samir Patel
11/20/2004 11:44:25 AM
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).

Scott Mitchell [MVP]
11/23/2004 8:41:29 PM
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
mitchell@4guysfromrolla.com
http://www.4GuysFromRolla.com

AddThis Social Bookmark Button