Solved

Disable linkbutton after clicked

Posted on 2006-06-19
6
625 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
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Login 17 50
IIS Authorization for Web Service 2 46
When should I use a controller? 3 34
jquery datatables, asp.net MVC 9 41
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

777 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