How to truly disable a linkbutton RRS feed

  • Question

  • User-101145231 posted

    After searching for a few hours for good looking solution to disable and reenable a asp.net linkbutton control from javascript I got this idea.

    *this reffers to the linkbutton

    Problem: when you run the following code it disables the look of the link however not the click event.

    this.disabled = false;

    first solution i found was to change the href first i tried changing the href to "" this disabled the click event however i could not reenable it. Even after reseting the href the button would not fire the postback.

    Next I tried setting the onClientClick attribute to return false this did not work either when the button was disabled it would still fire the javascript in the href.

    then I mapped the onclick event from the code behind to return false. this worked however when i modified the onclick event from javascript to return true when i wanted to reenable the link it did not work.

    Finally i figure out that i could do the following

                Dim LinkButton As LinkButton = DirectCast(sender, WebControls.LinkButton)
                LinkButton.Attributes.Add("onClick", "return !this.disabled;")

    This code allowed me to set the event serverside and control it using the disabled property of the linkbutton class in my client side code.

    I hope this helps the people that may run into the same issue as i did.

    in Firefox you have to also change the css class to look like a disabled link otherwise users will be clicking and not understanding why nothing is happening

    found a minor issue with this method. disabled is not a property of an anchor tag in firefox. this does not effect functionality if you set disabled property before you attempt to use it. im not sure/concerned if this is w3 standards complient as long as it works on each browser and it seems to do so.

    Thursday, March 25, 2010 1:55 PM

All replies

  • User-493604037 posted

    Thanks Brother!

    Tuesday, December 21, 2010 6:14 AM
  • User-558651039 posted

    At last!!! solution that works!

    Thank you so much!


    Monday, September 26, 2011 8:46 AM