Kev'n Roberts

May 2008 - Posts

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.

Session Dump Utility

I'm currently working on a project where we are storing quite a bit of data in Session for the user. Naturally, QA had a hard time testing whether or not something actually was stored in Session. So, we wrote a little page that showed the values of what we put in Session. The problem with this approach is that every time we added another item to Session, or removed an item, we would have to fix this page to include the new and remove the old. It got to be very tiresome.

I had just finished doing some work with reflection (my first time ever). And it occurred to me that I could use reflection to show everything that was stored in Session in such a way that it could be written once and never need to be updated.

Here's the basic rundown of what the utility does (see attached .zip file):

  1. On the page load, iterate over all items in Session
  2. Print the Key of the item
  3. If the value of the item is a native data type (int, bool, decimal -- including String and DateTime objects) print the value
  4. If the value is an object...
  5. Iterate over all the public properties of the object
  6. Print the Property Name
  7. If the value of the Property is a native data type, print it
  8. If it is an object, GOTO #5

In the end, I always get to a native data type (or String or DateTime), so we wouldn't end up in an endless loop. Here's a sample of what it displays:

 

As an added bonus, it will also display the approximate size of all the objects (in bytes/kilobytes).

This utility has been very helpful for me, to make sure I know what is in Session, without having to step through the code in debug mode and stop and interrogate the Session object to find the specific value (or values) I'm looking for. This has also been very helpful to QA so that they can see what is put into Session.
 

More Posts