onSubmit only works for buttons

T

Tina

I have some javascript that I want executed whenever my form is subitted so
I put onSubmit= "return myfunction();" in my <form clause on my aspx page.

If the user hits a button the javascript executes just fine. But if the
user changes the selection on a dropdown (that has AutoPostback=true) the
javascript does not get executed.

I want the javascript to execute whenever any control is hit that causes a
postback.

Anyone know why this is not working as I expect it to or what can be done to
get my desired results?

thanks,
T
 
G

Guest

Asp controls who autopostback use the code __doPostBack. I am not sure if
this code calls 'submit'.
--
Direct Email: Michael.Baltic@RemoveCharactersUpTo#NCMC.Com

Staff Consultant II
Enterprise Web Services
Cardinal Solutions Group
 
P

Peter Rilling

The following is from msdn.

"You can override this event by returning false in the event handler. Use
this capability to validate data on the client side to prevent invalid data
from being submitted to the server. If the event handler is called by the
onsubmit attribute of the form object, the code must explicitly request the
return value using the return function, and the event handler must provide
an explicit return value for each possible code path in the event handler
function.

The submit method does not invoke the onsubmit event handler."

The last sentence says it all.
 
I

intrader

Asp controls who autopostback use the code __doPostBack. I am not sure if
this code calls 'submit'.
Is your button a submit button?. If it is just a button no onSubmit is
triggered (you have to do your own)
 
G

G Dean Blake

Tina,
You have come accross a big fat hole in asp.net. Asp.net produces a
_doPostBack() javascript function using it's
page.RegisterOnSubmitStatement() but the problem is that code generated by
page.RegisterOnSubmitStatement() does not get executed when a page is
submitted using AutoPostBack. GOTCHA!!

There is an article at www.asptoday.com entitled DoPostBack Hijacking that
details how to get around this problem. you will need to subscribe to the
site to get the article but, in my opinion, it is well worth the money
because a 3 month subscription cost less than an hours work.
Regards,
G Dean Blake
www.deanblakely.com
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top