Tuesday, July 21, 2009

Maxlength for multiline textbox in ASP.NET page using AJAX

Easy solution for restricting text to MAXLENGTH in a multiline textbox, using Ajax MaskedEdit extender.

To get the effect of Maxlength=50, just attach the MaskedEdit extender to the multiline textbox and set the Mask value to ?{50}.

Following example shows a 'Maxlength' of 300.

<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Remarks") %>' Width="700px" TextMode="MultiLine"></asp:TextBox>

<cc1:MaskedEditExtender ID="MaskedEditExtender1" runat="server" Mask="?{300}" PromptCharacter="" TargetControlID="TextBox1">
</cc1:MaskedEditExtender>

2 comments:

agplaza said...

When I first read your solution I thought it was great. Unfortunately, after trying it, I realised it was't as good as it seemed. The problem is you can overwrite already typed text, while a proper length-limiting solution shouldn't let you do so unless you first delete some text.

Unknown said...

Dear Sir/Madam

Happy onam to you. we are a group of students from cochin who are currently building

a web portal on kerala. in which we wish to include a kerala blog roll with links to

blogs maintained by malayali's or blogs on kerala.

you could find our site here: http://enchantingkerala.org

the site is currently being constructed and will be finished by 1st of sep 2009.

we wish to include your blog located here

http://namaskardotnet.blogspot.com/


we'll also have a feed fetcher which updates the recently updated blogs from among

the listed blogs thus generating traffic to your recently posted entries.

If you are interested in listing your site in our blog roll; kindly include a link

to our site in your blog in the prescribed format and send us a reply to

enchantingkerala.org@gmail.com and we'll add your blog immediatly.

pls use the following format to link to us

Kerala

hoping to hear from you soon.

warm regards

Abhilash.k