Problem with custom validation

J

Jaime Stuardo

Hi everybody...

I am testing custom validation in a test ASPX page and it isn't working. I
followed a tutorial but when I compiled the code, the field isn't validated.

The tutorial says that I have to add a CustomValidator control, then set the
Text, ErrorMessage and ControlToValidate properties. In order to add a
custom function, I have to double click on the control and add my custom
function. After that, the control validation should work, but it didn't.

This is the ASPX code of the control:

<asp:CustomValidator id="CustomValidator1" runat="server" ErrorMessage="El
número debe ser par" ControlToValidate="TextBox7">Ese no es un número
par</asp:CustomValidator>

And this is the code-behind function:

private void CustomValidator1_ServerValidate(object objFuente,
System.Web.UI.WebControls.ServerValidateEventArgs objArgs)
{
int numero_par = int.Parse(objArgs.Value);
objArgs.IsValid = (numero_par % 2 == 0);
}

When I place a breakpoint in the function, it isn't called either.

What am I missing?

Thanks a lot in advance
Jaime
 
L

Lucas Tam

private void CustomValidator1_ServerValidate(object objFuente,
System.Web.UI.WebControls.ServerValidateEventArgs objArgs)
{
int numero_par = int.Parse(objArgs.Value);
objArgs.IsValid = (numero_par % 2 == 0);
}

When I place a breakpoint in the function, it isn't called either.

You didn't assign the event handler...


private void CustomValidator1_ServerValidate(object objFuente,
System.Web.UI.WebControls.ServerValidateEventArgs objArgs) handles
myCustomerValidator.servervalidate


Also... you may or may not want to assign ControlToValidate. I believe when
you have ControlToValidate set, it won't validate if the entry is blank.
 

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

Similar Threads

Custom Validation Cntrl 5
Custom validation wont trigger 1
Custom validation 3
custom validation 14
Custom validation For validating dates 1
checkbox validation 1
custom validation 1
Custom validation 4

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top