异常详细信息:System.Web.HttpException:无法修改Controls集合,因为控件包含代码块(即)。

编程入门 行业动态 更新时间:2024-10-28 10:27:15
本文介绍了异常详细信息:System.Web.HttpException:无法修改Controls集合,因为控件包含代码块(即)。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

异常详细信息: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 <%=

启动代码块首先,使用<%#而不是<%= : 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集合,因为控件包含代码块(即)。

本文发布于:2023-11-25 00:59:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627663.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:详细信息   控件   异常   代码   Controls

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!