How to prevent the user from clicking on a button more than once.

mike55

Contributor
Joined
Mar 26, 2004
Messages
727
Location
Ireland
Hi all

I am looking for code that will prevent the user from clicking on a particular button more than once. I got some C# code that is suppose to work. I converted this code into vb.net:
Code:
Dim sb As New System.Text.StringBuilder

sb.Append("if (typeof(Page_ClientValidate) == 'function') { ")
sb.Append("if (Page_ClientValidate() == false) { return false; }} ")
sb.Append("this.value = 'Please wait...';")
sb.Append("this.disabled = true;")
sb.Append(ClientScript.GetPostBackEventReference(Button1))

sb.Append(";")
Button1.Attributes.Add("onclick", sb.ToString())

The problem that I am getting is: "Value of type System.Web.UI.WebControl.Button cannot be converted into System.Web.UI.PostBackOptions". I am using the .net 2005 professional environment. Am suggestions for this problem?

Mike55.
 
PlausiblyDamp said:
What did the original C# code look like?

Code:
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("if (typeof(Page_ClientValidate) == 'function') { ");
sb.Append("if (Page_ClientValidate() == false) { return false; }} ");
sb.Append("this.value = 'Please wait...';");
sb.Append("this.disabled = true;");
sb.Append(this.Page.GetPostBackEventReference(this.Button1));
sb.Append(";");
this.Button1.Attributes.Add("onclick", sb.ToString());

I had to change the page.getpostbackeventreference to clientscript.getpostbackeventreference as .net 05 kept telling me there was an error.

A web site that I came across suggested using the following:
Code:
System.Threading.Thread.Sleep(2000)
However you have no way of knowing how long the sleep will have to be for.

Mike55.
 
It would seem that the solution to my problem is to leave the line: this.page.getpostbackeventreference(this.button1) as it is and not change is to this.clientscript.getpostbackeventreference(this.button1) as .net 05 wants.

Mike55.
 
Back
Top