异常详细信息:System.Web.HttpException:无法修改Controls集合,因为控件包含代码块(即)。 [英] Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. ).
问题描述
异常详细信息:System.Web.HttpException:无法修改Controls集合,因为控件包含代码块(即<%...%>)。
这是我怎么解决这个问题,
谢谢和问候
Ravi
Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
what error this is how i can solve this,
Thanks & Regards
Ravi
推荐答案
尝试使用<%#而不是<%=
Try starting the code block with <%# instead of <%=
启动代码块首先,使用<%#<启动代码块/ i>而不是<%= :
First, start the code block with <%# instead of <%=:
<head id="head1" runat="server">
<title>My Page</title>
<script type="text/javascript" src="<%# ResolveUrl("~/javascript/JScript.js") %>"></script>
</head>
这会改变从Response.Write代码块到数据绑定表达式的代码块。由于<%#...%> 数据绑定表达式不是代码块,因此CLR不会抱怨。在您的母版页中添加以下代码:
This changes the code block from a Response.Write code block to a databinding expression. Since <%# ... %> databinding expressions aren''t code blocks, the CLR won''t complain. Add the following code in your master page:
protected void Page_Load(object sender, EventArgs e)
{
Page.Header.DataBind();
}
参考类似的解决方案这里 [ ^ ]。
--Amit
Refer a similar solution here[^].
--Amit
只需从头到脚移动使用<%= asomething.SomeProperty%>的脚本。
just move your scripts which use <%= asomething.SomeProperty %>, from Head to Body.
这篇关于异常详细信息:System.Web.HttpException:无法修改Controls集合,因为控件包含代码块(即)。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!