开发者

Disable a HyperLink from code behind

开发者 https://www.devze.com 2023-01-10 20:07 出处:网络
In my project I need to disable a hyperlink based on some condition开发者_运维百科. So how can I do this from code behind using C#?in your aspx, add runat=\"server\" attribute to the tag:

In my project I need to disable a hyperlink based on some condition开发者_运维百科. So how can I do this from code behind using C#?


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;


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

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


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

0

精彩评论

暂无评论...
验证码 换一张
取 消