Custom Validator

G

Guest

Hello,

I am new to .NET, and a custom validator is giving me a lot of grief.

I want to use a Custom Validation control and for some reasons it's not firing the validation procedure. I am using .NET framework 1.0

Here is the declaration of the control

<asp:CustomValidator id="CustomValidator1" style="Z-INDEX: 103; LEFT: 304px; POSITION: absolute; TOP: 408px" runat="server" ErrorMessage="Bad input -- please correct" EnableClientScript="False" ControlToValidate="TextBox1"></asp:CustomValidator>

I also have a text box and a button on the form. When a user clicks a button, the following code does run:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If IsValid Then
'do something
End If
End Sub

I expect that when the line "IsValid" is executed, the validator will go into n event handler:

Private Sub CustomValidator1_ServerValidate(ByVal source As System.Object, ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) Handles CustomValidator1.ServerValidate
If TextBox1.Text = "" Then
source.isvalid = False
Else
source.isvalid = True
End If
End Sub


….but, for some reasons, this is not happening. The CustomValidator1_ServerValidate is never called. (I know that I could have used the Required Validator for the example as it's presented here, but actually I do need to use the Custom validator because the check condition is going to be much more complex.)

Your help is be greatly appreciated!

Evgueni
 
C

Chris R. Timmons

Hello,

I am new to .NET, and a custom validator is giving me a lot of
grief.

I want to use a Custom Validation control and for some reasons
it's not firing the validation procedure. I am using .NET
framework 1.0

Evgueni,

The CustomValidator control will not fire if the control it is
validating is empty.

Hope this helps.

Chris.
 
H

Hans Kesting

Chris R. Timmons said:
Evgueni,

The CustomValidator control will not fire if the control it is
validating is empty.

Hope this helps.

Chris.


And FYI, a CustomValidator doesn't need a "ControlToValidate". If you leave
that
empty, then it fires always.

Hans Kesting
 

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,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top