Kev'n Roberts

ValidationGroup on the ValidationSummary Control

Today I learned an important lesson about the ValidationSummary control. But first, some background.

The bug I was working on was this: the validation summary did not display the validation errors. The page would repost and redisplay, but there was no messaging as to what might be wrong.

The page was set up in a wizard sort of fashion with about three Panel controls that are displayed selectively, depending on which step the user is on. In order to prevent all the validation controls to fire every time a button is clicked, the various validators were assigned to different validation groups, one for each Panel. 

It took me about an hour before I discovered this truth:

"When you specify a value for the ValidationSummary property, only error messages from the validation controls that are part of the specified group are summarized. If you do not set a value for this property, all error messages from validation controls on the page that are not assigned to a validation group are summarized."

The first time I read it, I was in a hurry and didn't catch the very last part: "...that are not assigned to a validation group..." I guess it is important to read all the documentation.

My bug was that the ValidationSummary did not specify a validation group. According to the docs, that means that only validators that are not assigned a ValidationGroup will show up in the summary control. It was an easy fix (set the validation group when I set which panel to display), but it took me about an hour to figure it out.

Comments

W.Meints said:

That's actually rather quick. I didn't know that until now. Good to know since I use validation groups a lot.

# May 13, 2008 1:59 AM

Ian said:

Did you just set the validationgroup property on both validators, textboxes and validation summaries, or perform some other (eg page.validate) function on the action for switching panels?

# January 12, 2009 3:18 PM

Bogdan said:

Did anyone noticed that MS says "...ValidationSummary property..." There is no such property. There is a ValidationGroup property, yes, but no ValidationSummary. ValidationSummary is a control, not a property. Can this be just a typo from Microsoft, or I'm missing something?

I recently bumped into this while trying to debug a page with 2 ValidationSummary controls (one for "ValidationGroup1", the other for "ValidationGroup2"). Both summary controls show up when I submit the page. Both of them show all the error messages from individual control validators despite the setting of ValidationGroup property.

I'm stuck. I'm using UpdatePanels and this might be the cause. I don't know...

# May 19, 2009 3:02 PM

lekshmi said:

Very good post. I alomost spend an hour trying ti figure out the problem. Thanks so much!

# August 6, 2009 1:28 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)