Inject items in ValidationSummary control?

  • Thread starter Thread starter Christopher H. Laco
  • Start date Start date
C

Christopher H. Laco

First, a little background. I'm trying to forge ahead into ASP.NET 2.0.
I've dome many assemblies in C#, but I've yet to have to use ASP.NET.
I'm trying to forge ahead in getting some web/server controls created so
during a future conversion the work is already done for other programmers.

I've started created common controls used in various ecommerce
checkouts. For example, credit card validation, promo vcodes validation,
etc. Some sites use both, some sites use one. In ever case, they all
just do the right thing because their validation error messages go into
a ValidationSummary control. This is all well and good for server side
validation.

However, even if the server side validates user input, the backend
systems may still throw up errors about the data the user entered...like
the promo code has expired, the credit card is a private lable and has
options, etc, etc.


What I would like to do is inject those returned errors back into the
ValidationSummary component since they will be displayed the same way,
and the Page.IsValid would be True at that point. I have no clue where
to begin with such a task and am looking for pointers to the approach.

There could be in excess of 20 errors returned, so I didn't want to
create local validators that simply checked the return codes.

Any ideas?

Thanks,
-=Chris
 
use a System.Web.UI.WebControls.CustomValidator and place your server
side validation code in the ServerValidate handler.

The client side validation checks will all be done first and if they
all pass the page will post back at which point the CustomValidators
will be run.

Hope that helps,

Jan
 
Jan said:
use a System.Web.UI.WebControls.CustomValidator and place your server
side validation code in the ServerValidate handler.

The client side validation checks will all be done first and if they
all pass the page will post back at which point the CustomValidators
will be run.

Hope that helps,

Jan
I'm already using CustomValidators. The problem is, if I use 1
CustomValidator to validate data with the backend system, I need to
stuff many different ErrorMessages into the ValidationSummary, not just
the single ErrorMessage for that CustomValidator. Even if I stuff
multiple LI HTML into the ErrorMessage property, it gets wrapped in a
single LI during Render.

-=Chris
 
Ah I see,

Well just create a class with a static boolean attribute that stores
it's data in Session[...] like ValidationFailed.

When you start processing the serverside validators set it false;
Then set it true if a custom validator fails.
And make sure that each validator only runs if ValidationFailed is
false

Hope that helps
 
Back
Top