HOW TO: Display Required Field Validators at Page Load

by Donn Felker 20. July 2007 11:01

Sometimes when a page loads you'll want the user to be able to see the which fields are required. This is normally done by presenting an asterisk next to the fields that need to be populated/selected.

The RequiredFieldValidator does not automatically perform validation upon load, but here's some code that will allow you to do so:

I usually put this in the OnPreRender event handler as at that point everything is done processing on the page.

foreach (IValidator validator in Validators)
{
    if (validator is RequiredFieldValidator)
   {
     validator.Validate();
   }
}

This will ensure that the page's required field validators are validated when the page loads. Therefore giving the user the insight into the required fields.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Add comment


(Will show your Gravatar icon)  

  Country flag

biuquote
  • Comment
  • Preview
Loading



Powered by BlogEngine.NET 1.4.5.0
Theme by Mads Kristensen

About the author

Donn Felker

Senior Consultant
MCTS
ScrumMaster
Agile Practitioner

About Me | Books I Recommend

Gotta Pay The Bills


Tag cloud

    Popular Posts

    RecentComments

    Comment RSS

    Calendar

    <<  January 2009  >>
    MoTuWeThFrSaSu
    2930311234
    567891011
    12131415161718
    19202122232425
    2627282930311
    2345678

    View posts in large calendar