473,412 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,412 software developers and data experts.

Disable Submit Button on Post back and On Submit in ASP.net

Call this function from the Page_OnLoad event of your asp.net page.
This will prevent the user from doing multiple post backs or button
clicks.
This was designed to not disable the button, because asp.net 1.x will
not pick up the button click event.
Instead, it monitors the on submit event of the form and the
_doPostBack event of the asp.net page.
It overrides the _doPostBack and onsubmit events and checks whether
the page has already been submitted or posted back.
If the user does anything during a submit or postback, it is ignored.

The code below is using a submit button named "btnNext"; you can
change the code to reference your own button.
============Begin Code==================

Public Function PutOnSubmitButtonDisabler(ByRef oPage As Page)

If Not oPage.IsClientScriptBlockRegistered("PleaseWait") Then
oPage.RegisterClientScriptBlock("PleaseWait", "<script
type='text/javascript'>" & vbCrLf & _
"var PageIsProcessing = false;" & vbCrLf & _
"function PleaseWait(){" & vbCrLf & _
"if(Page_IsValid){" & vbCrLf & _
"if(PageIsProcessing==true){" & vbCrLf & _
"return false;" & vbCrLf & _
"}else{" & vbCrLf & _
"if(document.forms[0].btnNext !=
null){document.forms[0].btnNext.value = 'Processing...';}" & vbCrLf &
_
"PageIsProcessing = true;" & vbCrLf & _
"return true;" & vbCrLf & _
"}" & vbCrLf & _
"}" & vbCrLf & _
"}" & vbCrLf & _
"</script>")
End If

oPage.RegisterStartupScript("PleaseWaitOnPostBack" , "<script
type='text/javascript'>" & vbCrLf & _
"var __doPostBack__ = window.__doPostBack;" & vbCrLf & _
"window.__doPostBack = function(eventTarget, eventArgument) {" &
vbCrLf & _
"if(PageIsProcessing==true){" & vbCrLf & _
"}else{" & vbCrLf & _
"if(document.forms[0].btnNext !=
null){document.forms[0].btnNext.value = 'Processing...';}" & vbCrLf &
_
"__doPostBack__(eventTarget, eventArgument);" & vbCrLf & _
"PageIsProcessing = true;" & vbCrLf & _
"}" & vbCrLf & _
"}" & vbCrLf & _
"</script>")
oPage.RegisterOnSubmitStatement("PleaseWait",
"if(!PleaseWait()){return false};")
End Function

============End Code==================
Nov 18 '05 #1
2 8906
This assumes the browser has javascript enabled. How do you prevent multiple
submits in a purely server side way with .net?

"Ghafran Abbas" wrote:
Call this function from the Page_OnLoad event of your asp.net page.
This will prevent the user from doing multiple post backs or button
clicks.
This was designed to not disable the button, because asp.net 1.x will
not pick up the button click event.
Instead, it monitors the on submit event of the form and the
_doPostBack event of the asp.net page.
It overrides the _doPostBack and onsubmit events and checks whether
the page has already been submitted or posted back.
If the user does anything during a submit or postback, it is ignored.

The code below is using a submit button named "btnNext"; you can
change the code to reference your own button.
============Begin Code==================

Public Function PutOnSubmitButtonDisabler(ByRef oPage As Page)

If Not oPage.IsClientScriptBlockRegistered("PleaseWait") Then
oPage.RegisterClientScriptBlock("PleaseWait", "<script
type='text/javascript'>" & vbCrLf & _
"var PageIsProcessing = false;" & vbCrLf & _
"function PleaseWait(){" & vbCrLf & _
"if(Page_IsValid){" & vbCrLf & _
"if(PageIsProcessing==true){" & vbCrLf & _
"return false;" & vbCrLf & _
"}else{" & vbCrLf & _
"if(document.forms[0].btnNext !=
null){document.forms[0].btnNext.value = 'Processing...';}" & vbCrLf &
_
"PageIsProcessing = true;" & vbCrLf & _
"return true;" & vbCrLf & _
"}" & vbCrLf & _
"}" & vbCrLf & _
"}" & vbCrLf & _
"</script>")
End If

oPage.RegisterStartupScript("PleaseWaitOnPostBack" , "<script
type='text/javascript'>" & vbCrLf & _
"var __doPostBack__ = window.__doPostBack;" & vbCrLf & _
"window.__doPostBack = function(eventTarget, eventArgument) {" &
vbCrLf & _
"if(PageIsProcessing==true){" & vbCrLf & _
"}else{" & vbCrLf & _
"if(document.forms[0].btnNext !=
null){document.forms[0].btnNext.value = 'Processing...';}" & vbCrLf &
_
"__doPostBack__(eventTarget, eventArgument);" & vbCrLf & _
"PageIsProcessing = true;" & vbCrLf & _
"}" & vbCrLf & _
"}" & vbCrLf & _
"</script>")
oPage.RegisterOnSubmitStatement("PleaseWait",
"if(!PleaseWait()){return false};")
End Function

============End Code==================

Nov 19 '05 #2
You can use a variable in the user's session:
http://www.daveandal.net/books/6744/...one-click.aspx

"Stephen J. Kladich" <St*************@discussions.microsoft.com> wrote in
message news:F2**********************************@microsof t.com...
This assumes the browser has javascript enabled. How do you prevent multiple submits in a purely server side way with .net?

"Ghafran Abbas" wrote:
Call this function from the Page_OnLoad event of your asp.net page.
This will prevent the user from doing multiple post backs or button
clicks.
This was designed to not disable the button, because asp.net 1.x will
not pick up the button click event.
Instead, it monitors the on submit event of the form and the
_doPostBack event of the asp.net page.
It overrides the _doPostBack and onsubmit events and checks whether
the page has already been submitted or posted back.
If the user does anything during a submit or postback, it is ignored.

The code below is using a submit button named "btnNext"; you can
change the code to reference your own button.
============Begin Code==================

Public Function PutOnSubmitButtonDisabler(ByRef oPage As Page)

If Not oPage.IsClientScriptBlockRegistered("PleaseWait") Then
oPage.RegisterClientScriptBlock("PleaseWait", "<script
type='text/javascript'>" & vbCrLf & _
"var PageIsProcessing = false;" & vbCrLf & _
"function PleaseWait(){" & vbCrLf & _
"if(Page_IsValid){" & vbCrLf & _
"if(PageIsProcessing==true){" & vbCrLf & _
"return false;" & vbCrLf & _
"}else{" & vbCrLf & _
"if(document.forms[0].btnNext !=
null){document.forms[0].btnNext.value = 'Processing...';}" & vbCrLf &
_
"PageIsProcessing = true;" & vbCrLf & _
"return true;" & vbCrLf & _
"}" & vbCrLf & _
"}" & vbCrLf & _
"}" & vbCrLf & _
"</script>")
End If

oPage.RegisterStartupScript("PleaseWaitOnPostBack" , "<script
type='text/javascript'>" & vbCrLf & _
"var __doPostBack__ = window.__doPostBack;" & vbCrLf & _
"window.__doPostBack = function(eventTarget, eventArgument) {" &
vbCrLf & _
"if(PageIsProcessing==true){" & vbCrLf & _
"}else{" & vbCrLf & _
"if(document.forms[0].btnNext !=
null){document.forms[0].btnNext.value = 'Processing...';}" & vbCrLf &
_
"__doPostBack__(eventTarget, eventArgument);" & vbCrLf & _
"PageIsProcessing = true;" & vbCrLf & _
"}" & vbCrLf & _
"}" & vbCrLf & _
"</script>")
oPage.RegisterOnSubmitStatement("PleaseWait",
"if(!PleaseWait()){return false};")
End Function

============End Code==================

Nov 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Bruno Alexandre | last post by:
Hi guys, If I want to block a user to change a form after submiting, I add a function that will disable the submit button, but when I'm getting the form collection (using post or get...
1
by: Paul Oakfleet | last post by:
The script below will disable Submit button until user accept terms, and will redirect user to another page after clicking on Submit button. The script seems to work fine on my PC (Windows XP,...
2
by: techfuzz | last post by:
I scoured this group and others looking for the best way to disable a button after the first click to prevent multiple submissions, but never did find anything that worked like they said it would. ...
14
by: Sinity | last post by:
Anyone knows the method/codes to disable the clicked button after first click by using .aspx-- to prevent people to click many time when waiting for the server response. I tried to do this by...
3
by: Jeff | last post by:
I have a payment form with a submit button. A large percentage of users double-click the submit button thus submitting their payment information twice. I would like to use javascript to disable...
8
by: rodchar | last post by:
hey all, can someone please tell me if you can disable the scroll button for a dropdownlist. For example, when you select an item in a dropdownlist and it still has focus and you accidently hit...
16
by: Barry Gilmore | last post by:
Is there a way to disable a button after it is clicked? I am trying to avoid having someone click on it twice while they wait for it to process. Thank you!
5
by: Sehboo | last post by:
In my application, there are lot of processes which take several seconds. What we want is that once user clicks on a button (or link or whatever) and while we are processing that request, we don't...
6
by: =?Utf-8?B?Unlhbg==?= | last post by:
Hi, I found out that Text property is perserved, but disable/enable status is not preserved, especially I change this setting of a server side text box with client side javascipt and then post...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.