CustomValidator bug?

G

George Ter-Saakov

Hi.

I am fighting the CustomValidator strange behavior for second day already.
I created some test project which is only to reproduce the problem.

1. I created UserControl which has an only a Custom Validator
2. in UserControl::page_Load i set
CustomValidator1.IsValid = false;

3. I insert the User Control into the page and have a submit button there.


So when i run the project it shows me errors from CustomValidator (because
IsValid set to false)
But when i click submit button there is no error shown and Page.IsValid
returns true.


Am i missing something? Where should i set CustomValidator1.IsValid = false;
so the Page.IsValid would be set to false as well?


Thanks.
George.
 
H

Hans Kesting

George Ter-Saakov said:
Hi.

I am fighting the CustomValidator strange behavior for second day already.
I created some test project which is only to reproduce the problem.

1. I created UserControl which has an only a Custom Validator
2. in UserControl::page_Load i set
CustomValidator1.IsValid = false;

3. I insert the User Control into the page and have a submit button there.


So when i run the project it shows me errors from CustomValidator (because
IsValid set to false)
But when i click submit button there is no error shown and Page.IsValid
returns true.


Am i missing something? Where should i set CustomValidator1.IsValid = false;
so the Page.IsValid would be set to false as well?


Thanks.
George.

To implement a CustomValidator you need to handle the ServerValidate event.


private void CustomValidator1_ServerValidate(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args)
{
args.IsValid = false;
}


Hans Kesting
 
G

George Ter-Saakov

Got to the bottom of it.
It turned out that I must provide handler CustomValidator.ServerValidate and
set args.IsValid = false in it.

Otherwise the IsValid is reset to true.

Which is not very good design. I would say if ServerValidate event is not
handled then IsValid must stay as is.

Thanks.
George.
 

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

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,044
Latest member
RonaldNen

Latest Threads

Top