RadioButton AutoPostBack does not execute JavaScript

M

M

Hi everybody,

I have a Web form with something like:
<form id="Form1" method="post" onsubmit="javascript:submitForm();"
runat="server">

I need the JavaScript function submitForm() to execute everytime the form is
submitted.

I also have two RadioButtons with AutoPostBack set to true.

The problem is when I click on one of the radio button, the form is posted
back, but the JavaScript is not executed. Is there a way to get some
JavaScript to execute everytime the Web form is posted back?

Thanks in advance.
 
J

JustinBlat

The radio buttons you are using do not submit the form the same way a
button does. The OnSubmit event of the form object only fires when a
button of type Submit fires the event. When a radio button ( or
checkbox, or dropdownlist) is set to autopostback, that postback occurs
via the __doPostback function generated automatically by ASP.NET. This
function takes an eventTarget and an eventArgument, and posts this data
back to the sever. To see an example of this, view the HTML source on
your page. One way to get around this problem is to override the
__doPostback event in javascript, and execute your script from there.
One such example can be found here:

http://weblogs.asp.net/vga/archive/2004/03/01/NoMoreHijackingOfDoPostBackInWhidbey.aspx

Hope this has been helpful, Good Luck!
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top