CustomValidators without ServerValidate event

H

headware

Lately, I've been using the CustomValidator control without the
ServerValidate event handler. For instance, if I'm importing a file and
there is an IOException thrown, I report back to the user that there
was a problem by setting the IsValid property of a CustomValidator to
false and returning.

The real reason I do it this way is so that the error message will be
displayed in the ValidationSummary control at the top of the page.
Handling the ServerValidate event of the CustomValidator doesn't really
make sense, because there's nothing to really validate, I just want to
display the message in the ValidationSummary.

I seem to be reading that this isn't a good idea. It appears to be
working fine, and I was wondering if there is a problem with doing this
that I'm not seeing.

Thanks,
Dave
 
P

Peter Blum

I don't know if it will break in a future ASP.NET 2.0 version. But the
validation framework doesn't care much how IsValid is set. It's OnPreRender
method detects IsValid is false and displays the error message. Nothing more
to it.

--- Peter Blum
www.PeterBlum.com
Email: (e-mail address removed)
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx
 
H

headware

Thanks for the reply. Let's say for a second that this did break in
ASP.NET 2.0. How would you achieve the same effect? As far as I know
you can't dynamically add error messages to a ValidationSummary
control. I guess you could use a separate Label for each error or make
your own custom control to display error messages the way you want.
However, I don't much like either of those options. Does anyone else
have any other suggestions?

Dave
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top