First of all, it is usually better to use one of the validator controls so
that in the code you can check whether everything passed validation by doing
something like
If Me.IsValid Then
End If
Your technique could be used with a CustomValidator, but CustomValidators
require a PostBack before the user can see the error message and ASP.NET
cannot attempt to generate JavaScript to perform client-side validation.
This is the best way of using one of the validators to limit the number of
characters I could find. Also, using a RegularExpressionValidator is less
code because you do not need to implement a ServerValidate event. In my
opinion, since the TextBox is a server-side control, there should be an
option for having this validation created automatically.
--
Nathan Sokalski
nj********@hotmail.com http://www.nathansokalski.com/
"Cor Ligthert [MVP]" <no************@planet.nlwrote in message
news:O%****************@TK2MSFTNGP02.phx.gbl...
Nathan,
Can you explain to us why using a regularExpressionValidator is better
than
myTexbox.Text.Lenght 250
I am curious about that
Cor
"Nathan Sokalski" <nj********@hotmail.comschreef in bericht
news:O8**************@TK2MSFTNGP02.phx.gbl...
>As we probably know, the MaxLength property of the TextBox control only
works when the TextMode property is SingleLine or Password. I want to
limit the number of characters a user can enter into a MultiLine TextBox
to 250. I figured the best way to do this would be with a
RegularExpressionValidator. For my ValidationExpression I figured I would
use:
.{0,250}
However, the . does not include the \n character. On the page:
ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxfund/html/c82dc689-7e82-4767-a18d-cd24ce5f05e9.htm
there were a bunch of RegexOption members, one of which (the singleline
member) looked like it could do what I wanted. However, I was having
trouble understanding how to specify what options I wanted. If anyone
could help me here, I would appreciate it. Thanks.
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/