在asp.net控件中,此上下文不支持代码块
我正在创建一个html表。 我想要隐藏表格行。 我将特定行的属性runat=server
和id
,但该行中的客户端代码类似于以下代码。
调用此行后,我收到此错误。
在asp.net控件中,此上下文不支持代码块。
以下是我的示例代码:
G Medical
将runat='server'
添加到HTML控件时,您更改了渲染,并且内部不支持代码块。 因此,如果有需要更改的属性(样式?类?),您可能不得不这样做:
your code here
做这样的事情:
> your code here
注意:从tr
删除了runat='server'
。 然后在您的代码隐藏中,您可以执行以下操作:
protected string GetRowProperties() { return "class='myclass'"; // something like this }
您可以使用数据绑定来控制控件的可见性。 这应该可以解决你的问题。
some content... This content will only be rendered if strFlag is "d" or "y" more content...
在OnLoad方法中,您需要将DataBind()方法调用到PlaceHolder或包含它的任何控件,如tr或偶数Page:
protected override void OnLoad(EventArgs e) { base.OnLoad(e); Page.DataBind(); }