Solved

Disable linkbutton after clicked

Posted on 2006-06-19
6
614 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 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