gpt4 book ai didi

asp.net - 内联代码没有作为后面的代码执行

转载 作者:行者123 更新时间:2023-12-03 18:05:47 25 4
gpt4 key购买 nike

关注 :另一篇文章(Set Visible property with server tag <%= %> in Framework 3.5)也为这个问题提供了更详细的答案。

我很好奇为什么在这种情况下内联代码不表现为代码隐藏。

我有一个包含如下设置的类:

// Collection of Settings
public static class FeatureControl
{
public static bool SettingName = true;
}

后面的代码按预期执行。
Label1.Visible = FeatureControl.SettingName; //true
Label2.Visible = !FeatureControl.SettingName; //false

无论 SettingName 的值如何,内联代码始终显示两个标签:
<asp:Label ID="Label1" Visible="<%#FeatureControl.SettingName%>"  runat="server" >  </asp:Label>
<asp:Label ID="Label2" Visible="<%#FeatureControl.SettingName != true %>" runat="server" ></asp:Label>

最佳答案

由于<%# %>是一个数据绑定(bind)表达式,我很确定你必须调用 Page.DataBind() .试试看:

protected void Page_Load(object sender, EventArgs e) 
{
DataBind();
}

关于asp.net - 内联代码没有作为后面的代码执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25066818/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com