【发布时间】:2021-11-05 05:13:35
【问题描述】:
我正在支持一个非常古老的遗留应用程序,该应用程序即将被删除,它是用 aspx 编写的。我在页面 (Example.aspx) 中有一个 <div> 元素,我试图根据复选框选中的值在后面的代码 (Example.aspx.cs) 中使其可见。但是我不断收到这个Cannot get inner content of '' because the contents are not literal 错误,因此我的 div 没有被渲染。我提到了这篇 SO 帖子:Cannot get inner content of '' because the contents are not literal,其中提到这不适用于在服务器上运行的控件,即runat="server"。我无法访问建议的这篇 SO 帖子的一个答案中引用的 Wordpress 网址:Cannot get inner HTML - 而这个 (Cannot manage to change the inner html of a div element) 不适用于我的问题。
例子.aspx:
<div id="testID" runat="server"> <!--some content ---></div>
Example.aspx.cs:
protected void checkBoxName_CheckedChanged(object sender, EventArgs e)
{
if(!checkBoxName.Checked)
testID.Visible = true; //The exception is thrown here
}
【问题讨论】:
-
请在出现
Cannot get inner content of '' because the contents are not literal错误的地方添加代码。 -
@SelimYildiz 抛出异常这一行
testID.Visible = true;。我用评论编辑了问题