Validate on page load

J

Jeremy Chapman

I have several required field validators on my page. Normally, when a
submit button is pressed, the validators display with a red * character
beside the corresponding field, and a validation summary displays a popup
message.

When the page is loaded I want to display all the red * characters, so the
user knows beforehand which fields are required, but I don't want to cause
the validation summary to display at this point. It should display only
when the user submits the page. How can this be done?
 
L

Lucas Tam

I have several required field validators on my page. Normally, when a
submit button is pressed, the validators display with a red *
character beside the corresponding field, and a validation summary
displays a popup message.

When the page is loaded I want to display all the red * characters, so
the user knows beforehand which fields are required, but I don't want
to cause the validation summary to display at this point. It should
display only when the user submits the page. How can this be done?


Try calling Page.Validate in Page.Load, but set the visibility of your
validation summary to false.
 
D

darrel

When the page is loaded I want to display all the red * characters, so the
user knows beforehand which fields are required, but I don't want to cause
the validation summary to display at this point. It should display only
when the user submits the page. How can this be done?

Validators are really meant to validate a field upon submission...not to
indicate a field is required to begin with. Why not just put an astrisk in
the HTML itself to indicate that it's required?

-Darrel
 
J

Jeremy Chapman

I could do this, but in case we added or changed required fields I wanted to
be able to just change the validators and have it all work. If I add *
characters explicitely then I have to move them around too. I just like to
keep maintenance to a minimum as much as possible.
 
G

Guest

I realize this may be a little "above and beyond", but if your concern is
that you want to minimize the impact when changing the required fields, you
could create a custom control that includes both your "required field
indicator", and your "validator", and use that control instead of the built
in validator.

It would be quite simple to do....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top