Fire Custom Validator on AutoPostback

T

tshad

I am trying to fire the CustomValidator when I leave the Email field.
Following is the code. It does PostBack, but the CustomValidator doesn't
seem to be firing.

<asp:TextBox AutoPostBack="true" Columns="45" ID="email"
runat="server" TextMode="SingleLine" />
<asp:CustomValidator
ControlToValidate="email"
OnServerValidate="ValidateEmail"
Font-Size="10"
Display="Dynamic"
Text="Not Valid !"
runat="server" />
<asp:RequiredFieldValidator
ControlToValidate="email"
Text="Email Required"
runat="server" />
<asp:RegularExpressionValidator ControlToValidate="email" Text =
"Invalid Email Address!"
ValidationExpression="\S+@\S+\.\S{2,3}" runat="server" />

What tells it to execute?

Thanks,

Tom
 
K

Karl Seguin

Tshad,
You need to manually fire off the server-side validation process with
Page.Validate() From your example, this would likely be something like:

Private Sub email_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles email.TextChanged
Page.Validate()
If Page.IsValid Then
'stuf here
End If
End Sub


Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/index.aspx - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
 
T

tshad

Karl Seguin said:
Tshad,
You need to manually fire off the server-side validation process with
Page.Validate() From your example, this would likely be something like:

Private Sub email_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles email.TextChanged
Page.Validate()
If Page.IsValid Then
'stuf here
End If
End Sub

How do I prevent it from firing when I push a button (as it would already
have been done from the autopost)?

If I have 3 buttons on my screen, does it get executed regardless of which
button is pushed?

Thanks,

Tom
 
T

tshad

Karl Seguin said:
It gets executed wherever you put Page.Validate() so if you put it in
the
event of each control and check for Page.IsValid then it'll execute in all
three. If you only put it in a single event, then it'll only happen
there...

I don't have Page.Validate() anywhere in my code and it still fires.

Tom
 

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,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top