mike55 Posted April 19, 2006 Posted April 19, 2006 Hi all Here is the best solution that I have come across for preventing double clicks... 1. Create a module, and call it GlobalModule. 2. Add the following method/function... Public Sub ButtonClickEventGovenor(ByVal btn As System.Web.UI.WebControls.Button, ByVal PageHasValidators As Boolean) Dim sJavaScript As String If PageHasValidators Then sJavaScript = "if (typeof(Page_ClientValidate) == 'function') {if (Page_ClientValidate())" & _ "{this.value='Please wait...';this.disabled = true;" & _ btn.Page.GetPostBackEventReference(btn) & ";}}" Else sJavaScript = "this.value='Please wait...';this.disabled = true;" & _ btn.Page.GetPostBackEventReference(btn) End If btn.Attributes.Add("onclick", sJavaScript) End Sub 3. Every page that you need to prevent a double click, do the following. 3a. declare a global variable: dim pBackHandler as new GlobalModule 3b. add the following line into the page load method: Call pBackHandler.ButtonClickEventGovenor(btnAdd, PageHasValidators:=True) If the page has no validators, just set the variable PageHasValidators to false. The question that I have now, is how can I throw up a javascript messagebox or confirmation dialog and use it? Mike55. Quote A Client refers to the person who incurs the development cost. A Customer refers to the person that pays to use the product. ------ My software never has bugs. It just develops random features. (Mosabama vbforums.com)
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.