Display Modes of Validator Controls

by ashic 15. June 2009 23:04

By default, asp.net validators are positioned right next to the control they validate. You can move them in the markup, but wherever you put them, they occupy an area equal to the area required to display the Text property (or if the Text is not present, then the ErrorMessage property). We may not want that. We may want them to only occupy space when they’re displayed, or not display them at all (and showing the error message in a validation summary only). The validators have a property called display, which can be set to one of three values: Static, Dynamic and None. Setting it to Static will mean the validator will occupy space even when there’s no error. Dynamic means that it won’t occupy space when there isn’t an error, but will show up when there is. None means that the validator’s Text (or ErrorMessage) isn’t displayed at all and doesn’t occupy any space. In this case, you’ll need to use a ValidationSummary control to be able to display the ErrorMessage.

Let’s look at a bit of markup that has three required field validators having different settings for Display. To the right of each validator, I’ve added the text “dummy” to signify where the validator’s display area ends. Markup:

val-pos-1

 

Now let’s fire up the page and see what it look like in the browser:

val-pos2

Notice that since the first validator had a display of static, there’s a space equal to the space needed to display the Text of the first validator next to the first text box. The second and third validators had display set to “Static” and “None” respectively. Hence, there’s no space between the second and third textboxes and they’re respective “dummy” texts. Now, lets hit submit:

val-pos3

Notice that the Text of the first two validators are displayed next to the text boxes, but the third one’s Text is not shown at all. This is because the third validator’s display was set to none. Notice that the error message of all three validators are displayed in the validation summary.

 

Hope that helps.

Shout it
Share or Bookmark this post…
  • DotNetKicks
  • LinkedIn
  • Technorati
  • msdn Social
  • del.icio.us
  • Digg
  • Reddit
  • StumbleUpon
  • Slashdot
  • Live
  • Google
  • Facebook
Categories: ASP.NET | Validation

Comments

6/3/2009 6:09:27 AM #

trackback

Display Modes of Validator Controls

Thank you for submitting this cool story - Trackback from DotNetShoutout

DotNetShoutout

6/3/2009 6:10:24 AM #

trackback

Display Modes of Validator Controls

You've been kicked (a good thing) - Trackback from DotNetKicks.com

DotNetKicks.com

6/3/2009 6:22:09 AM #

trackback

Display Modes of Validator Controls

In this article, Ashic Mahtab shows how to control how a validator is displayed on an asp.net page. Note

Community Blogs

6/3/2009 3:56:51 PM #

pingback

Pingback from rapid-dev.net

Display Modes of Validator Controls | rapid-DEV.net

rapid-dev.net

6/19/2009 10:33:31 PM #

trackback

Display Modes of Validator Controls

You are voted (great) - Trackback from WebDevVote.com

WebDevVote.com

7/1/2009 7:08:45 PM #

flowers fast coupon

Great post - Just subscriped to your RSS feed.. Thanks

flowers fast coupon United States

7/2/2009 1:15:48 AM #

pingback

Pingback from answerspluto.com

list of urls - 5 « Answers Pluto

answerspluto.com

9/28/2009 7:59:36 PM #

Pinball games

I am not really sure if best practices have emerged around things like that, but I am sure that your great job is clearly identified. I was wondering if you offer any subscription to your RSS feeds as I would be very interested and can?t find any link to

Pinball games United States

10/26/2009 10:58:36 AM #

san diego real estate

I was very pleased to find this site. I wanna thank you for this great post. It's really cool.

san diego real estate United States

11/10/2009 10:38:10 PM #

waggi

Great post.

waggi United States

11/15/2009 10:14:34 PM #

Annuitaetendarlehen Rechner

Hi
I just realized that I visited your blog again while searching for information related to ASP.net. I think it's a good indicator for your Blog Wink

Annuitaetendarlehen Rechner

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading




Powered by BlogEngine.NET 1.5.1.29
Theme by Ashic Mahtab

Stats