Jump to content
Xtreme .Net Talk

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


Recommended Posts

Posted

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:

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.

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)

Posted
What did the original C# code look like?

 

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:

System.Threading.Thread.Sleep(2000)

However you have no way of knowing how long the sleep will have to be for.

 

Mike55.

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)

Posted

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.

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)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...