CustomValidators without ServerValidate event

  • Thread starter Thread starter headware
  • Start date Start date
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
 
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
 
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
 
Without having ASP.NET 2.0 in front of me, how should I know what the right
strategy is? The fact is, you are worrying about something that is most
likely not an issue. If ASP.NET 2.0 breaks it, I'm sure you will come up
with a solution like creating unique CustomValidators only when something is
invalid and attaching a ServerValidate method which will always set the
result to indicate its invalid.

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