ANP
ANP

Reputation: 15607

Disable a HyperLink from code behind

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

Upvotes: 5

Views: 22074

Answers (3)

eduardo Pisoni
eduardo Pisoni

Reputation: 1

myHyperLink.Enabled = false; does not work with <a> links

Instead use aria-disabled="true"

In your method add this:

myHyperLink.Attributes.Add("aria-disabled", "true");

links:

https://a11y-guidelines.orange.com/en/articles/disable-elements/#:~:text=It%20is%20still%20possible%20to,is%20indicated%20as%20being%20disabled

How to add custom attributes to ASP.NET controls

Upvotes: 0

Sudhir Sonu Kumar
Sudhir Sonu Kumar

Reputation: 11

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

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

Upvotes: 0

onof
onof

Reputation: 17367

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;

Upvotes: 11

Related Questions