Can't use asp:CustomValidator

K

K Viltersten

I've followed the instructions for setting up a validation
of my forms (link below). For some reason, the
evaluation doesn't take place. My husband said he won't
help me on this one because it's easy. It's doesn't feel
that easy, so i'm not sure if he teases or means it... :(
http://msdn.microsoft.com/en-us/library/f5db6z8k.aspx

In fact, i don't seem to even enter the evaluation method
when i try to run the site in the debugger. However,
altering the name of it creates an error.

<form id="form1" runat="server">
<div>
<asp:Label ID="InfoOnstatus" runat="server">
No info yet! </asp:Label><br />
<asp:TextBox ID="TextBox1" runat="server" /><br />
<asp:CustomValidator ID="CustomValidator1" runat="server"
ValidateEmptyText="true"
ControlToValidate="TextBox1" OnServerValidate="TextValidate"
ErrorMessage="Invalid!"></asp:CustomValidator>
</div>
</form>

....
protected void TextValidate(
object sender, ServerValidateEventArgs e) {
InfoOnstatus.Text = "validated field";
if (e.Value == "qw")
e.IsValid = true;
else
e.IsValid = false;
}
....

What's wrong here? How can i troubleshoot it?
 
K

K Viltersten

Perhaps i should add that i'm looking for dynamic
validaton. I.e. validation as the user types. If the
test is that the string is supposed to be between
3 and 7 characters long i would like the status of
the validator to switch twice when they type in
e.g. all the digits.
 
B

bruce barker

you have wo issues. first, the server validaton will only run if you
call Page.IsValid (say in onload). second server validation only happens
after postback. the customvalidator supports client side validtion (via
ClientValidationFunction), but its called on lost focus (onblur). if you
want validation on char by char you will need to write custom client
side code. get a good javascript book.


-- bruce (sqlwork.com)
 
M

miher

K Viltersten said:
Perhaps i should add that i'm looking for dynamic validaton. I.e.
validation as the user types. If the
test is that the string is supposed to be between 3 and 7 characters long
i would like the status of
the validator to switch twice when they type in
e.g. all the digits.

Hi,
Try using a RegularExpressionValidator for this and You won't need to write
javascript. For example You can easily write a regexp that matches only 3-7
long strings.

I don't know if validators support what You willing ot do, to validate at
every keystroke, but You can use ValidatorValidate function for example from
the onkeyup (client-side) event of the textbox to force validation.

Hope You find this useful.
-Zsolt
 
K

K Viltersten

Try using a RegularExpressionValidator for this and You won't need to
write javascript. For example You can easily write a regexp that matches
only 3-7 long strings.

I don't know if validators support what You willing ot do, to validate at
every keystroke, but You can use ValidatorValidate function for example
from the onkeyup (client-side) event of the textbox to force validation.

I'll look into it. Thanks!

As i understand, as long as i do it on client-side, i'll
need to play with JavaScript, right?
 
M

miher

K Viltersten said:
I'll look into it. Thanks!

As i understand, as long as i do it on client-side, i'll
need to play with JavaScript, right?

Hi,
If You use the validators as they are, You don't have to write any
javascript, but if You have more expectations then You might have to write
more or less.

-Zsolt
 

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

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top