aceinthehole
aceinthehole

Reputation: 5222

ASP Validator Controls - can i have controls occupy the same location?

I am using a regular expression validator on multiple fields in a forum. They are all checking for the same thing, and to save space I'd like any of the validation messages to show up in the same space on the page. (They are checking for a valid email address). The problem I am running into, is that they are in their own space, sequentially on the page, and I would like them to occupy the same real estate.

Can this be done without resorting to doing a post back and dynamically hiding or showing controls on page load? Or, can I attach multiple controls to the exact same regular expression validator control?

Upvotes: 2

Views: 2033

Answers (3)

Akil
Akil

Reputation: 21

Adding display as dynamic worked for me.

Upvotes: 2

David
David

Reputation: 73564

If you're talking about how the validators seem to take up screen real-estate whether they're shown or not, you can set the "display" property of the validators to "dynamic".

This way they only take up space if there is an invalid entry, and the validator needs to show. This way, you can set them all next to each other, and only the ones displaying a message due to a validation failure will take up space in that location. (If there are more than one, then all of the ones that are visible due to validation failure will show up in a flow layout. You can make them show up on top of each other by including a <br />' tag in the Validation Text, but that's a bit of a hack).

The default is "static" which forces them to take up real-estate even if the message isn't being shown.

(I know that was probably clear as mud, so there's an article here with screenshots - look at figures 7.6 and 7.7)


If, however, you want all your messages at the top of the page, or in one place, rather than next to the controls in question, then @Sir Crispalot's answer is the best solution IMO.

Upvotes: 4

Sir Crispalot
Sir Crispalot

Reputation: 4844

Take a look at the ValidationSummary control. You can aggregate all of your validation errors into the same place and put it where you like. Link the ValidationSummary to the individual validation controls with their ValidationGroup property.

You can still show the whole message (or, say just an asterisk) next to the invalid fields.

Upvotes: 3

Related Questions