show requiredfieldvalidator text when page first displays?

Discussion in 'ASP .Net Web Controls' started by Bryan Ax, May 11, 2004.

  1. Bryan Ax

    Bryan Ax Guest

    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
    Bryan Ax, May 11, 2004
    #1
    1. Advertising

  2. Bryan Ax wrote:
    > 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

    http://www.4GuysFromRolla.com
    http://www.ASPFAQs.com
    http://www.ASPMessageboard.com

    * When you think ASP, think 4GuysFromRolla.com!
    Scott Mitchell [MVP], May 11, 2004
    #2
    1. Advertising

  3. Bryan Ax

    Bryan Ax Guest

    "Scott Mitchell [MVP]" <> wrote in message news:<>...
    > Bryan Ax wrote:
    > > 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
    >
    > 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?
    Bryan Ax, May 12, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Peter Row
    Replies:
    0
    Views:
    281
    Peter Row
    Mar 3, 2004
  2. Chumley Walrus
    Replies:
    1
    Views:
    12,163
    =?Utf-8?B?QnJpYW4gQnJvd24=?=
    Dec 16, 2004
  3. Sparky Arbuckle

    Only First Shopping Cart Item Displays

    Sparky Arbuckle, Feb 20, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    292
    Sparky Arbuckle
    Feb 20, 2005
  4. Preben Zacho

    RequiredFieldvalidator displays error too early

    Preben Zacho, Oct 23, 2007, in forum: ASP .Net Web Controls
    Replies:
    4
    Views:
    175
    john123
    Oct 30, 2007
  5. Chris Curtis
    Replies:
    2
    Views:
    182
    Chris Curtis
    May 17, 2006
Loading...

Share This Page