RadioButton AutoPostBack does not execute JavaScript

Discussion in 'ASP .Net' started by M, Mar 26, 2005.

  1. M

    M Guest

    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.
     
    M, Mar 26, 2005
    #1
    1. Advertisements

  2. M

    JustinBlat Guest

    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!
     
    JustinBlat, Mar 27, 2005
    #2
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.