IValidator - multiple error messages

  • Thread starter Peter Morris [Air Software Ltd]
  • Start date
P

Peter Morris [Air Software Ltd]

Hi all

I want a validator which
A) Doesn't validate a control
B) Is able to report more than one error

The reason for this is that I am validating a whole business object based on
a list of expressions, rather than individual controls.

Is it possible to do this? Could someone please tell me how, because I can
only see IValidator and the ability to add a single error from my single
class (I don't want to use multiple validators).

Thanks


--
Pete
====
Audio compression components, DIB graphics controls, FastStrings
http://www.droopyeyes.com

Read or write articles on just about anything
http://www.HowToDoThings.com

My blog
http://blogs.slcdug.org/petermorris/
 
P

Peter Morris [Air Software Ltd]

Hi

Thanks for your detailed response!
* You can certainly write out a single string, containing all of your
error messages.

This approach would create a string too large for displaying.
* Recommendation: Use the ValidationSummary control. Add a PlaceHolder
control somewhere to the page. For each error message that you get back,
create a CustomValidator object with its ErrorMessage assigned and its
Display property set to None. Set it to an "evaluation function" that
simply evaluates as "invalid". This way, you are creating a list of error
messages on the fly that will appear in the ValidationSummary.

This sounds like the best option by far. This will still leave me with the
problem of my other posting "WebControl with non-WebControl property". This
validator would have to be a WebControl, but I need to point it to a
component which is not a webcontrol. If you have any insight into this
problem I would appreciate it if you would post a response.

Finally, what should I do about ControlToValidate in my new validator? It
seems silly to ask the developer to point it at any control just for the
sake of it. Can I some how turn off the check for ControlToValidate !=
null?

Thanks again for your help, I really appreciate it!


--
Pete
====
Read or write articles on just about anything
http://www.HowToDoThings.com

My blog
http://blogs.slcdug.org/petermorris/
 
P

Peter Morris [Air Software Ltd]

Actually, what I think I will do is to expose the "MultipleValidator" via an
interface, and then have a property on my non WebControl component to this
interface. The component will then add error messages to the new validator
rather than the validator fetching the errors.

Thanks for your help, I really appreciate it!


--
Pete
====
Read or write articles on just about anything
http://www.HowToDoThings.com

My blog
http://blogs.slcdug.org/petermorris/
 
P

Peter Morris [Air Software Ltd]

Argh!!! So close!!!

The technique you suggested works brilliantly, almost perfectly.

I can add errors to my MultiValidator like so
multiValidator1.AddError("This works");
and they appear in the validation summary, great!

The bit that doesn't work is that I am trying to add errors in a
Button.Click, for example.....

private void SaveButton_Click1(object sender, System.EventArgs e)
{
multiValidator1.AddError("This doesn't work");
}//SaveButton_Click

The code steps through, adds the errors, but then they don't appear on the
validationsummary. I suspect that at this point the rendering has already
been done hasn't it?

I definately do not want to check for some errors unless I click the Save
button, simply because there is a DB operation involved and I don't want to
execute that code for every Page.Load when I could execute it only for
Save.Click.

Is there a way I can resolve this?

If not, is there a way I can check if Save.Click is the cause of the
postback?

Thanks


--
Pete
====
Read or write articles on just about anything
http://www.HowToDoThings.com

My blog
http://blogs.slcdug.org/petermorris/
 

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,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top