?
Solved

Disabling SUBMIT button to prevent multiple clicks.

Posted on 2007-10-17
8
Medium Priority
?
1,136 Views
Last Modified: 2012-05-05
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.




0
Comment
Question by:Homer2040
  • 4
  • 3
8 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20093881
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
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20093927
or something like


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

0
 

Author Comment

by:Homer2040
ID: 20094033
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20094132
As I said. You cannot disable the submit button when you submit.

Instead set a switch and test it
0
 
LVL 18

Accepted Solution

by:
tusharashah earned 1000 total points
ID: 20094208
You can set UseSubmitBehavior to false and add OnClientClick like following to get what you want..

<asp:Button ID="btnSubmit" runat="server" Text="Submit" UseSubmitBehavior="false" OnClientClick="this.disabled=true;this.value='Please Wait...';" OnClick="btnSubmit_Click" />

-tushar
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20094228
Yikes!
0
 

Author Comment

by:Homer2040
ID: 20094490
mplungjan,

I am still getting multiple submits.

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

H.
0
 

Author Comment

by:Homer2040
ID: 20094585
mplungjan,

It looks like tusharashah's suggestion is working.

Thanks.

H.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses
Course of the Month17 days, 11 hours left to enroll

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question