Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Can't use asp:CustomValidator

Reply
Thread Tools

Can't use asp:CustomValidator

 
 
K Viltersten
Guest
Posts: n/a
 
      03-23-2009
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?





 
Reply With Quote
 
 
 
 
K Viltersten
Guest
Posts: n/a
 
      03-23-2009
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.

--
Regards
K Viltersten

 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      03-23-2009
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)

K Viltersten wrote:
> 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.
>
> --
> Regards
> K Viltersten
>

 
Reply With Quote
 
miher
Guest
Posts: n/a
 
      03-23-2009


"K Viltersten" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed)...
> 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.
>
> --
> Regards
> K Viltersten


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

 
Reply With Quote
 
K Viltersten
Guest
Posts: n/a
 
      03-23-2009
> 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?

--
Regards
K Viltersten

 
Reply With Quote
 
miher
Guest
Posts: n/a
 
      03-24-2009


"K Viltersten" <(E-Mail Removed)> wrote in message
news:ejJljk$(E-Mail Removed)...
>> 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?
>
> --
> Regards
> K Viltersten


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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Could not use ''; file already in use. M K ASP .Net 11 04-09-2008 11:35 AM
where to use CPLD & where to use FPGA? kulkarku@math.net VHDL 6 03-06-2006 07:27 AM
How do I know when to use the Viewstate and when to use the posted data? :-) Simon ASP .Net 1 11-09-2004 02:32 AM
Can I use XPath or something to a remote Mac or Linux box and just query an xml file, not using web services and use encyrption? jake ASP .Net 0 07-06-2004 02:16 PM
Cannot use the profile "default" because it is in use, not. please.post@yur.re.ply Firefox 1 07-04-2004 03:41 AM



Advertisments