2
2obvious
I picked up a really nifty function that allows me to count "words" in
a string of text.
CountWords()
I'd like to use this function to validate some form fields. One field
should have no more than 100 words, the other should have no more than
20.
I can't think of a way to do this in ASP.NET
<asp:customvalidator id="OurCustomValidator"
ControlToValidate="OurTextBox"
OnServerValidate="CountWords(20)"
ErrorMessage="Error"
runat="server" />
won't work, because I can't pass arguments to CountWords() in ASP.NET
using this approach.
If I wrote two functions, one that checked for 100 words, the other
that checked for 20 (I know: totally bad practice)
<asp:customvalidator id="OurCustomValidator"
ControlToValidate="OurTextBox"
OnServerValidate="CountWords1()"
ErrorMessage="Error"
runat="server" />
I couldn't do anything with the results. I must return Page.IsValid,
not some random true/false value.
<asp:comparevalidator id="validator2"
ControlToValidate="CountWords(OurTextBox)"
Operator="LessThanEqual"
ControlToCompare="100"
ErrorMessage="Error"
runat="server" />
Can I even /do/ this (use my control as a function parameter)?
If anyone knows of a way to do this (I could keep guessing up theories
forever, please someone who /knows/) it would be much appreciated.
a string of text.
CountWords()
I'd like to use this function to validate some form fields. One field
should have no more than 100 words, the other should have no more than
20.
I can't think of a way to do this in ASP.NET
<asp:customvalidator id="OurCustomValidator"
ControlToValidate="OurTextBox"
OnServerValidate="CountWords(20)"
ErrorMessage="Error"
runat="server" />
won't work, because I can't pass arguments to CountWords() in ASP.NET
using this approach.
If I wrote two functions, one that checked for 100 words, the other
that checked for 20 (I know: totally bad practice)
<asp:customvalidator id="OurCustomValidator"
ControlToValidate="OurTextBox"
OnServerValidate="CountWords1()"
ErrorMessage="Error"
runat="server" />
I couldn't do anything with the results. I must return Page.IsValid,
not some random true/false value.
<asp:comparevalidator id="validator2"
ControlToValidate="CountWords(OurTextBox)"
Operator="LessThanEqual"
ControlToCompare="100"
ErrorMessage="Error"
runat="server" />
Can I even /do/ this (use my control as a function parameter)?
If anyone knows of a way to do this (I could keep guessing up theories
forever, please someone who /knows/) it would be much appreciated.