How to disable html anchor tag of master page in other page?

3.4k Views Asked by At

My master page has anchor tag,which i want to disable on other page.But the disable property of anchor tag does not work.

Below is the code i have used.

Dim LinkLogout As HtmlAnchor
LinkLogout = CType(Master.FindControl("LogOutLi"), HtmlAnchor)          
LinkLogout.Disabled = True
2

There are 2 best solutions below

0
On BEST ANSWER

I got the way to disable completely an anchor tag:

Dim LinkLogout As HtmlAnchor
LinkLogout = CType(Master.FindControl("LogOutLi"), HtmlAnchor)
LinkLogout .HRef = "javascript:void(0)"
3
On

Setting the Disabled property will put a disabled attribute on the anchor tag. However, disabled is not a valid attribute for an anchor tag so for browsers like Firefox, it will not work. Funny enough, I tried it in IE and it works.

I don't know the full extent of what you're doing and I believe there would be a better way of doing what you need but for the purpose of solving your issue, you can set add an onclick event to return false and the anchor should act as if it was disabled.

Dim LinkLogout As HtmlAnchor
LinkLogout = CType(Master.FindControl("LogOutLi"), HtmlAnchor)
LinkLogout.Attributes.Add("onclick", "return false;")