Home All Groups Group Topic Archive Search About

Validation controls validate before form submits

Author
24 Jun 2005 6:29 PM
TS
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!

Author
27 Jun 2005 6:14 AM
[MSFT]
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
Author
27 Jun 2005 10:58 PM
TS
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!

Show quoteHide quote
"[MSFT]" <lukez***@online.microsoft.com> wrote in message
news:cdOKC%23teFHA.4856@TK2MSFTNGXA01.phx.gbl...
> 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
>
>
>
>
Author
27 Jun 2005 11:32 PM
TS
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

Show quoteHide quote
"TS" <manofsteele1@nospam.nospam> wrote in message
news:uRaXHv2eFHA.2740@TK2MSFTNGP10.phx.gbl...
> 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]" <lukez***@online.microsoft.com> wrote in message
> news:cdOKC%23teFHA.4856@TK2MSFTNGXA01.phx.gbl...
> > 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
> >
> >
> >
> >
>
>
Author
28 Jun 2005 3:00 AM
[MSFT]
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
Author
28 Jun 2005 2:23 PM
TS
thanks

Show quoteHide quote
"[MSFT]" <lukez***@online.microsoft.com> wrote in message
news:IxuSQ24eFHA.4300@TK2MSFTNGXA01.phx.gbl...
> 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
>