Solved

Disable linkbutton after clicked

Posted on 2006-06-19
6
616 Views
Last Modified: 2012-06-27
Hi,

I'm having trouble disabling a linkbutton right after it is clicked so that the user cannot click it again in rapid succession and have the event run multiple times.

I've tried several things. Obviously setting linkbutton1.enabled = false at the beginning of the sub and setting linkbutton1.enabled = true at the end of the function doesn't work, but I also tried, setting a session variable when it is clicked and then looking to see if the session variable is set and if it is don't run the function, but that doesn't work either.

Currently, I have an onclick handler attached to the button which runs a vbscript function that disables the button on the client side and that doesn't work. I would think this would be a common problem, does anyone have a solution?
There must be a solution because this would really mess up banking sites, etc.

On some sites I've seen programmers put a message that says "Only click this button once.", but there must be a better way than that?

Here is my code

'**************************Page load

cmdRemove.Attributes.Add("onclick", "removeAns();")
handlemsg()

'**************************Handle Message

 'Takes a snapshot and removes the selected subject plan from the accommodation plan
    Private Sub handlemsg()
        If (Request.Form("hdnremove")) = YES Then
            'Calls the snapshot and remove
            Try
                Remove()
            Finally
                Session("sesAccRemove") = False
            End Try

        End If
    End Sub

'*************************VBScript
      <script language="vbscript">
            
   Dim lang
   lang = "<%=request.queryString("strLang")%>"
    dim mess1, mess2
    if ucase(lang) = "E" then
   mess1 = "You are about to remove this plan...Continue?"
       else
   mess1 = "Vous êtes sur le point d'éffacer ce plan. Poursuivre?"
   
   End if
   
      function removeAns()
      Dim MyButton
set MyButton = document.getElementById("cmdRemove")
if MyButton.disabled = false then
MyButton.disabled = true
                  If Msgbox(mess1,vbYesNo + vbExclamation) = vbYes Then
                    document.forms(0).hdnremove.value = "YES"                            
                  Else
            document.forms(0).hdnremove.value = "NO"
                End If
      end if
            End Function
      

            </script>
0
Comment
Question by:Gezna
  • 3
  • 2
6 Comments
 
LVL 9

Expert Comment

by:tolgaong
ID: 16934305
ok. you have to use javascript.
First,
linkButton1.Attributes.Add("onclick", "MoveObject()"))  => you write the javascript function's name here after the event name.

Then, at the html side, you write the javascriptcode
<script>
 function MoveObject()
{
document.getElementById("<%=button1.ClientID %>").style.left = "10px";
}
</script>


The code is more or less as above.
I hope it helps you.
0
 
LVL 9

Expert Comment

by:tolgaong
ID: 16934320
sorry, the javascript code should be

document.getElementById("<%=button1.ClientID %>").style.enabled= false;
0
 
LVL 20

Expert Comment

by:REA_ANDREW
ID: 16934337
document.getElementById("<%=button1.ClientID %>").style.enabled= false;

that is wrong,

document.getElementById("<%=button1.ClientID %>").disabled = false;

also, I have found from experience, that if you use javascript to disable the button, onclick, onmouseup and down, the sub routine fails to fire,  I would advice you do this

in your asp:button tag simply put this in as an attribute

onmouseup="this.style.display='none';"
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 20

Accepted Solution

by:
REA_ANDREW earned 500 total points
ID: 16934347
so to use with attributes you could have this

linkButton1.Attributes.Add("onmouseup", "this.style.display = 'none';"))

to validate what I said about the sub routine not firing try any one of these

linkButton1.Attributes.Add("onmouseup", "this.disabled = true;"))
linkButton1.Attributes.Add("onmousedown", "this.disabled = true;")) //<-----this will obviously not work
linkButton1.Attributes.Add("onclick", "this.disabled = true;"))
0
 

Author Comment

by:Gezna
ID: 16952032
Hi REA,

I actually found that, but yes you are right, I ended up using this.style.display = 'hidden' so you don't even see it. Is this what none does as well? you just don't see it?
0
 
LVL 20

Expert Comment

by:REA_ANDREW
ID: 16952061
thanks for the grade,

yes none does the same thing, it hides it

:-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

910 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now