You can also declare a public boolean and use that. You will need to use DataBind()
if the link is outside a GridView/Repetater etc.
public bool isVisible = true;
protected void Page_Load(object sender, EventArgs e)
{
DataBind();
}
Now you can use that on the aspx.
<a runat="server" visible='<%# isVisible %>' href="~/">Home</a>
However you can also use a ternary operator based on a different variable or class value within your code.
public int myValue = 11;
public Book myBook = new Book() { category = "Fantasy" };
protected void Page_Load(object sender, EventArgs e)
{
DataBind();
}
Now you can set the visibility based on myValue
, even though it is not a Boolean.
<a runat="server" visible='<%# myValue > 10 ? true : false %>' href="~/">Home</a>
//or
<a runat="server" visible='<%# myBook.category == "Fantasy" ? true : false %>' href="~/">Home</a>