Solved

Disable linkbutton after clicked

Posted on 2006-06-19
6
631 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
Industry Leaders: 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

617 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