%=和%#的怪异错误.
以前一直以为除了数据源绑定以外 <%= % 与<%#没有什么区别.
但是今天上午遇到的一个问题却让我费尽了牛劲. 特地记录下来 ,以后兄弟们少走弯路哈.
事情经过是这样的.在我的项目中的模板页上需要动态的加载脚本 我一直是这样做的.
<script type="text/javascript" src="<%=SysConfig.ApplicationPath%>/Ext/Js/ext-base.js"></script>
但是当我添加了一个新的模板页并应用后报下图错误,
Server Error in '/' Application.
--------------------------------------------------------------------------------

The Controls collection cannot be modified because the control contains code blocks (i.e. <%
%>).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <%
%>).

Source Error:


Line 115: override protected void OnInit(EventArgs e)
Line 116: {
Line 117: base.OnInit(e);
Line 118:
Line 119: if (Cookie != null)

Source File: E:\chen\work\EngineNew\Steed\WebSite\Base\BasePage.cs Line: 117

Stack Trace:
多方查找也没有得到解决.后来在网友提示下将其中的<%=%>更改为<%#%> 问题就解决了。
但就近是什么机制却不是很明白。只知道<%=%>其实相当于Response.Write的缩写,<%#%>是.net中的标准数据绑定的格式,其他的就搞不明白了 。
后来在一篇文章上看到“
但是今天上午遇到的一个问题却让我费尽了牛劲. 特地记录下来 ,以后兄弟们少走弯路哈.
事情经过是这样的.在我的项目中的模板页上需要动态的加载脚本 我一直是这样做的.
<script type="text/javascript" src="<%=SysConfig.ApplicationPath%>/Ext/Js/ext-base.js"></script>但是当我添加了一个新的模板页并应用后报下图错误,
Server Error in '/' Application.
--------------------------------------------------------------------------------
The Controls collection cannot be modified because the control contains code blocks (i.e. <%
%>).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
Exception Details: System.Web.HttpException: The Controls collection cannot be modified because the control contains code blocks (i.e. <%
%>).
Source Error: 

Line 115: override protected void OnInit(EventArgs e)
Line 116: {
Line 117: base.OnInit(e);
Line 118:
Line 119: if (Cookie != null)

Source File: E:\chen\work\EngineNew\Steed\WebSite\Base\BasePage.cs Line: 117 
Stack Trace: 
但就近是什么机制却不是很明白。只知道<%=%>其实相当于Response.Write的缩写,<%#%>是.net中的标准数据绑定的格式,其他的就搞不明白了 。
后来在一篇文章上看到“
This works fine for simple expressions. The difference here is that <%= %> expressions are embedded into the ASP.NET output as part of the generated Parse Tree class, whereas the <%# %> expressions are embedded at runtime.
” 一句话 , 原来是绑定的时机不同哈 。大家在以后注意哦

Line
浙公网安备 33010602011771号