Reputation: 2289
I have a hyperlink in a usercontrol that I'd like to set visibility by using a declarative property, i.e.
<asp:HyperLink ImageUrl="/images/icons/rss.png" Visible="<%# ShowRssIcon %>" ID="FeedHyperLink" runat="server"></asp:HyperLink>
However, it always remains visible, even if ShowRssIcon is false. ShowRssIcon is a simple property set on the usercontrol. Even setting ShowRssIcon to always return false results in the hyperlink showing.
However, setting Visible="false"
or Visible="true"
manually works as expected. Also, setting the property in the code behind on Page_Load
event also works.
Any ideas? Thanks.
Upvotes: 1
Views: 1259
Reputation: 23571
Your snippet doesn't show any call to DataBind so are you sure there is one? BTW if this hyperlink is not in a databound control like ListView or GridView it is far better to set the property from the code behind.
Upvotes: 2
Reputation: 52241
Since <%# expressions
are evaluated at DataBind()
time, if you used that, then you need to call DataBind();
method at PreRenderComplete like..
protected void Page_PreRenderComplete(object sender, EventArgs e)
{
DataBind();
}
Upvotes: 5