Take the 2-minute tour ×

In my project I need to disable a hyperlink based on some condition. So how can I do this from code behind using C#?

share|improve this question
Im assuming you mean a client-side anchor tag? If that's the case, you can't. You'll have to do it with javascript. (or make the anchor tag a server-side asp.net control) –  RPM1984 Aug 5 '10 at 10:20
Also, is this a WebForms based or an MVC based application? –  Manfred Aug 5 '10 at 10:21
add comment

1 Answer

up vote 5 down vote accepted

in your aspx, add runat="server" attribute to the tag:

<a id="myHyperLink" runat="server">...</a>

in Page_load method:

if( condition )
    myHyperLink.Enabled = false;
share|improve this answer
add comment

Your Answer


