【问题标题】:ASP.NET 4.0 Server TagsASP.NET 4.0 服务器标签
【发布时间】:2012-08-03 13:06:14
【问题描述】:

我们正在将 ASP.NET 项目从 2.0 版迁移到 4.0 版

在以前的版本中,我指定了以下代码行:

<asp:CheckBox runat="server" ID="chkContentFilter" 
       Text="<%# SearchResultDictionary.ContentFilter %>" 
       OnCheckedChanged="chkFilterCheckbox_ValueChanged" AutoPostBack="True"
       EnableViewState="True" ></asp:CheckBox>

问题是在 ASP.NET 4.0 中 &lt;%# %&gt; 服务器标签没有将数据映射到控件。

当然有一种解决方法可以在代码隐藏中设置控件文本。但我很感兴趣有没有办法在 aspx 布局上绑定文本?

【问题讨论】:

  • 你那里的东西似乎很好你能告诉我们你遇到了什么错误吗?也许更多关于“SearchResultDictionary.ContentFilter”
  • 我没有收到任何错误。只是在文本字段中空文本。我需要的是设置这个文本,注意控件不在数据绑定控件中。

标签: asp.net asp.net-4.0


【解决方案1】:

您必须在容器上调用 DataBind() 或自行控制&lt;%# %&gt; 才能被评估:

Data-Binding Expressions

标记:

<asp:CheckBox runat="server" ID="chkContentFilter" 
       Text='<%# SearchResultDictionary.ContentFilter %>' 
       OnCheckedChanged="chkFilterCheckbox_ValueChanged" AutoPostBack="True"
       EnableViewState="True" ></asp:CheckBox>

代码隐藏:

chkContentFilter.DataBind();

【讨论】:

    猜你喜欢
    • 2011-01-18
    • 2015-03-12
    • 1970-01-01
    • 2011-06-27
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多