Validation controls validate before form submits

Discussion in 'ASP .Net Web Controls' started by TS, Jun 24, 2005.

  1. TS

    TS Guest

    I have a page that spawns a new window. You select an item in it and it sets
    a hidden input box on the parent page using javascript, then it submits the
    parent and closes itself.

    There are required field validators on the parent page. During this
    javascript submit, the validation isn't occurring - which is good. The bad
    part is that when the page comes back from the server, the validation
    messages are now displayed. The user never had a chance to set the dropdowns
    because they weren't visible until now.

    Thinking about why its occurring made me wonder
    1. why the validators don't validate when the popup window's javascript
    submits the form (window.parent.form.submit()) .
    2. why does the errors display only when the page is rendered and not when
    the user clicks the submit button to submit the form?

    thanks a bunch!
    TS, Jun 24, 2005
    #1
    1. Advertising

  2. TS

    [MSFT] Guest

    Hello,

    The validation was done in the form's onsubmit event:

    <FORM language=javascript id=Form1 name=Form1 onsubmit="if
    (!ValidatorOnSubmit()) return false;" action=WebForm1.aspx method=post>

    When you click a button on the form, this event was fired. If it was not
    validated, the form won't be submited. However, when you submit it out of
    the form with script, this event was fired but the form was still submited
    even if it return false. This is why you got form submited and the
    validation message still occur.

    Luke
    [MSFT], Jun 27, 2005
    #2
    1. Advertising

  3. TS

    TS Guest

    What can i do to make it so the form keeps posting like it does currently,
    but the validation doesn't make it fail until after the popup is closed and
    the user clicks submit button on parent form. Otherwise i have error
    messages displayed without the user having a chance to populate them?

    (I'll try to dynamically add these controls just after the popup window
    closes and see if that will work)

    thanks!

    "[MSFT]" <> wrote in message
    news:cdOKC%...
    > Hello,
    >
    > The validation was done in the form's onsubmit event:
    >
    > <FORM language=javascript id=Form1 name=Form1 onsubmit="if
    > (!ValidatorOnSubmit()) return false;" action=WebForm1.aspx method=post>
    >
    > When you click a button on the form, this event was fired. If it was not
    > validated, the form won't be submited. However, when you submit it out of
    > the form with script, this event was fired but the form was still submited
    > even if it return false. This is why you got form submited and the
    > validation message still occur.
    >
    > Luke
    >
    >
    >
    >
    TS, Jun 27, 2005
    #3
  4. TS

    TS Guest

    that didn't work.

    I dont' know why it is validating. The control is created AFTER the form is
    submitted - maybe the form already knows that validation failed, so it goes
    ahead and shows all the error messages.

    What can I do?

    thanks

    "TS" <> wrote in message
    news:...
    > What can i do to make it so the form keeps posting like it does currently,
    > but the validation doesn't make it fail until after the popup is closed

    and
    > the user clicks submit button on parent form. Otherwise i have error
    > messages displayed without the user having a chance to populate them?
    >
    > (I'll try to dynamically add these controls just after the popup window
    > closes and see if that will work)
    >
    > thanks!
    >
    > "[MSFT]" <> wrote in message
    > news:cdOKC%...
    > > Hello,
    > >
    > > The validation was done in the form's onsubmit event:
    > >
    > > <FORM language=javascript id=Form1 name=Form1 onsubmit="if
    > > (!ValidatorOnSubmit()) return false;" action=WebForm1.aspx method=post>
    > >
    > > When you click a button on the form, this event was fired. If it was not
    > > validated, the form won't be submited. However, when you submit it out

    of
    > > the form with script, this event was fired but the form was still

    submited
    > > even if it return false. This is why you got form submited and the
    > > validation message still occur.
    > >
    > > Luke
    > >
    > >
    > >
    > >

    >
    >
    TS, Jun 28, 2005
    #4
  5. TS

    [MSFT] Guest

    Since you use the validation control, why do you need to submit the form
    even the validation is not true? I think there is two work around here:

    1. Set some default values in the controls so that the validation is true;
    2. Don't use Validation control.

    Luke
    [MSFT], Jun 28, 2005
    #5
  6. TS

    TS Guest

    thanks

    "[MSFT]" <> wrote in message
    news:...
    > Since you use the validation control, why do you need to submit the form
    > even the validation is not true? I think there is two work around here:
    >
    > 1. Set some default values in the controls so that the validation is true;
    > 2. Don't use Validation control.
    >
    > Luke
    >
    TS, Jun 28, 2005
    #6
    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. Robert V
    Replies:
    1
    Views:
    1,176
    Jeremy Fluhmann
    Jul 21, 2003
  2. Scott M.

    Run JavaScript before Form Submits

    Scott M., Nov 17, 2003, in forum: ASP .Net
    Replies:
    14
    Views:
    7,060
    Joe Gass
    Nov 18, 2003
  3. Stan
    Replies:
    1
    Views:
    2,518
    Jacob Yang [MSFT]
    Dec 3, 2003
  4. Mad Scientist Jr
    Replies:
    1
    Views:
    533
    bruce barker
    Mar 5, 2004
  5. =?Utf-8?B?QWxleCBNYWdoZW4=?=

    User Controls with Form fields & Multiple Submits

    =?Utf-8?B?QWxleCBNYWdoZW4=?=, May 7, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    407
Loading...

Share This Page