show requiredfieldvalidator text when page first displays?

B

Bryan Ax

One of the things I seem to be missing about validators...

I have a form with several required fields. Right now, I use the
following on my requiredFieldValidators.

Text=**
ErrorMessage="Something more elaborate"

When I validate the page, it displays all of the text alongside each
field that is incorrect, and displays a validationsummary of all
errors. However, what I can't seem to get to work is, when you first
load the page, show the text alongside each required field as a "hint"
of which fields are required. I know I could do this by adding
additional labels, but that seems like overkill. Is there no way to
show the text when the page is initialized, but NOT show the
validationsummary until the user submits the form?

Sincerely,

Bryan Ax
 
S

Scott Mitchell [MVP]

Bryan said:
One of the things I seem to be missing about validators...
[snip]
Is there no way to
show the text when the page is initialized, but NOT show the
validationsummary until the user submits the form?

Brian, try calling the Validate() method of the Page class explicitly on
page load. In your Page_Load event handler, try:

Sub Page_Load(...)
If Not Page.IsPostBack then
Page.Validate()
End If

...
End Sub

This (untested code) ought to do the trick.

Happy Programming!

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
 
B

Bryan Ax

Scott Mitchell said:
Bryan said:
One of the things I seem to be missing about validators...
[snip]
Is there no way to
show the text when the page is initialized, but NOT show the
validationsummary until the user submits the form?

Brian, try calling the Validate() method of the Page class explicitly on
page load. In your Page_Load event handler, try:

Sub Page_Load(...)
If Not Page.IsPostBack then
Page.Validate()
End If

...
End Sub

This (untested code) ought to do the trick.

Happy Programming!

--

Scott Mitchell
(e-mail address removed)
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!

Scott:

I've tried that. However, when you call Validate(), it causes the
ValidationSummary to display - I don't want the validationsummary to
display up-front - it makes too many messages display. I only want the
text of the validators to display next to each control - I don't want
the ErrorMessages to display in the validationSummary. I've also tried
then explicitly hiding the validationSummary on page_load, but then
when you try and submit the form, the client-side error-checking
happens, and if the page isn't valid, the validation summary does not
appear.

Any other thoughts?
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top