Solved

Disable linkbutton after clicked

Posted on 2006-06-19
6
628 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

739 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