asp.net当修改header时提示:The Controls collection cannot be modified because the control contains code blo...

it2026-05-19  2

The Problem:

后台代码:

HtmlGenericControl jsGC  =   new  HtmlGenericControl( " script " ); jsGC.Attributes.Add( " type " " text/javascript " ); jsGC.Attributes.Add( " src " " http://www.cnblogs.com/js/Cookie.js " ); Page.Header.Controls.Add(jsGC);

 提示错误:

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)

The Solution:

A. 把Header中的带有<%=...% >这样的代码移出。

B. 把代码放入placeholder

C. (1). 把<%=..%>改为:<%# ...%>

    (2). 在page_load函数中增加:Page.Header.DataBind();

D. 动态生成。

 

参考资料:http://leedumond.com/blog/the-controls-collection-cannot-be-modified-because-the-control-contains-code-blocks/

 

 

 

 

 

转载于:https://www.cnblogs.com/lfzwenzhu/archive/2010/03/30/1700430.html

最新回复(0)