5

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

onof
  • 16,907
  • 7
  • 47
  • 84
ANP
  • 14,647
  • 21
  • 55
  • 79
  • 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 05 '10 at 10:20
  • 1
    Also, is this a WebForms based or an MVC based application? – Manfred Aug 05 '10 at 10:21

2 Answers2

11

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;
onof
  • 16,907
  • 7
  • 47
  • 84
0

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

in Page_load method: if(condition) ep_sms.HRef = "#";