Validation controls validate before form submits

T

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!
 
M

[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
 
T

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!
 
T

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
 
M

[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
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top