Link to home
Start Free TrialLog in
Avatar of Homer2040
Homer2040

asked on

Disabling SUBMIT button to prevent multiple clicks.

Experts,

I have a .NET applicataion form that is called form a Master page. The application's SUBMIT button needs to NOT allow multiple clicks.

I have tried this in the Page_Load event and verified it's added:

     btnSubmit.Attributes.Add("onSubmit", "this.disabled=true;this.value='Please wait...';this.form.submit()");

but it's still allowing multiple clicks and multiple submissions.

Any ideas?

Thanks.

H.




Avatar of Michel Plungjan
Michel Plungjan
Flag of Denmark image

You do NOT want to disable the submit then submit the form..
there is no onsubmit on a button, it is on the form.
onclick is what you wanted

perhaps this is what you want

<script>
var submitted = false;
</script>


and add onsubmit of the form
if (submitted) return false; submitted=true;


Michel
or something like


btnSubmit.Attributes.Add("onclick", "if (this.form.getAttribute(submitted)) return false;
this.form.setAttribute('submitted',true); this.value='Please wait...'");

Avatar of Homer2040
Homer2040

ASKER

mplungjan,

Thanks for the catch, I did mean for it to be "onClick" on the button.
After correcting that (at least the behavior changed), the button is disabling (greying out) and the text is changing (Please Wait...), but the form is not submitting. It postsback like there is validation errors and there's not.

H.
As I said. You cannot disable the submit button when you submit.

Instead set a switch and test it
ASKER CERTIFIED SOLUTION
Avatar of tusharashah
tusharashah

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
mplungjan,

I am still getting multiple submits.

I think there was another suggestion...let me see.

H.
mplungjan,

It looks like tusharashah's suggestion is working.

Thanks.

H.