tags:

views:

51

answers:

2

I have an anchor link like:<a id="linkOwner" runat="server"></a> In my codebehind I am disabling it based on some condittions like:linkOwner.Disabled = true; But still the link is click-able.How to fix it?

A: 

If you use an ASP LinkButton control I think you can just disable it on the server side and it'll properly disable it on the client. Not positive on that though. Another method is to use javascript. In the past I have used jQuery to add a click event to the disabled anchor with a empty event that returns false. Something like:

function disabler(){ return false; }
$('#linkOwner').click(disabler);
//to reactive the link
$('#linkOwner').unbind('click', disabler);

The return false lets jQuery know not to bubble up the event.

Sean Copenhaver
A: 

There are two solutions:

  1. Change the anchor tag to an <asp:HyperLink> then you can set the Enabled property as you see fit.

  2. You need to add an attribute to the control as in

    linkOwner.Atributes["disabled"] = "disabled";

Philip Smith