MrClan MrClan - 1 year ago 54
Javascript Question form is not getting submitted when "onsubmit" event calls a javascript function

the situation is :

I want to disable all the controls on the page(possibly using an overlayed div), on the submit of a form, so that the user cannot click on other buttons, till the page is still processing the postback. So, I used the form's "onsubmit" event to call a javascript function that does the same. But now that function is being called, but the form do not get posted at all. I even tried, using "return true;" as the last line of my JavaScript function, but still the form does not get posted.

This is my javascript function :

function DoThis()
alert('this form is about to be submitted...');
return true;

and this is my form tag:

<form id="form1" runat="server" onsubmit="DoThis();">

What's is wrong here??? Also, let me know if there is some other way that would serve my purpose??? Thanks.

EDIT : I'm not referring to ajax calls here, since updatepanels already have features to enable this behaviour. I want this functionality for the entire page, even when a button outside an update panel is clicked resulting into full-postback and not just for ajax-calls(since the user normally has sufficient time to click 2 or 3 buttons, by the time the page get's redirected or reloaded).

Answer Source

Through a series of hit-n-trials, I finally figured out that I was missing the "return" keyword to add in my form tag. So, I modified my form tag as :

<form id="form1" runat="server" onsubmit="return DoThis();">

Silly things eat a lot of time. Probably, in-experience.