Limit asp:textarea to 100 chars on client side?

G

Guest

Is there a way to limit an asp:textarea to 100 chars on the client side? The
db only accepts 100 and chops the rest off.
 
K

Kevin Spencer

Use validation.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
 
G

Guest

I mean, I want them to stop at 100 before they hit submit. Like javascript.
But so I can still programatically read the control.
 
G

Guest

A multy line textarea does not use the maxlength attribute.

Custom validators require a postback, and a recompile of the codebehind,
which I can't do right now.
 
G

Guest

txtRemarks.Attributes.Add("onkeypress","return remarksLength()");

function remarksLength()
{
if (document.all('txtRemarks').value.length >= 100)
{
//alert('Remarks cant be more than 120 characters');
return false;
}
return true;
}
 
G

Guest

I simply made this form into it's own project so that I could compile it
separately. Then I did the Attributes.Add and the javascript. (I knew the
javascript, but was hoping to avoid having to do something that would involve
a compile.)
 
G

Guest

I've always used custom validators, never could seem to get the standard ones
to work, or if I used standard (out of the box) validators with custom ones,
the standards would fire client-side but the custom wouldn't until postback.
So if the user had 2 issues, they would hit 'Continue' see the msg for the
first (client-side) validator, fix it, hit 'Continue' again, THEN see the msg
for the custom validator.

So, when you say I could easily use clientside validation, when I already
have compiled code behind that I can't change, and I don't see how a standard
validator could validate a textarea length, I am genuinly curious.

Can you post your response here?
 
K

Kevin Spencer

if (document.getElementById("YourTextArea").value.length > 100)
alert("Whatever you want to say");
return (false);

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Neither a follower
nor a lender be.
 

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

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top