Attention: Another post(Set Visible property with server tag <%= %> in Framework 3.5) provides a more verbose answer to this question too.
I'm curious why the inline code does not behave as the code-behind in this case.
I have a class that contains settings as follows:
// Collection of Settings
public static class FeatureControl
{
     public static bool SettingName = true;
}
Code Behind executes as expected.
Label1.Visible = FeatureControl.SettingName; //true
Label2.Visible = !FeatureControl.SettingName; //false
Inline Code always shows both labels, regardless of the SettingName's value:
<asp:Label ID="Label1" Visible="<%#FeatureControl.SettingName%>"  runat="server" >  </asp:Label>
<asp:Label ID="Label2" Visible="<%#FeatureControl.SettingName != true %>"  runat="server" ></asp:Label>
                Since <%# %> is a databinding expression, I'm pretty sure you have to call Page.DataBind(). Give it a try:
protected void Page_Load(object sender, EventArgs e) 
{
     DataBind();
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With