内容包括一句: var a="<%=Request.ApplicationPath %>";
放在asp.net的<header>里就会报错,放在<body>里不报错。而如果去掉这一句就放在哪里都不报错。
我的问题是
1.asp.net里的javascript放在哪里比较好。
2.为什么在<header>里要求不能有<% ... %>)?请从asp.net的页面生成的角度来解释这个要求的必然性。
Server Error in '/WebApp' 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: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:
[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
System.Web.UI.ControlCollection.AddAt(Int32 index, Control child) +2105879
System.Web.UI.PageTheme.SetStyleSheet() +345
System.Web.UI.Page.OnInit(EventArgs e) +2057570
System.Web.UI.Control.InitRecursive(Control namingContainer) +321
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +692
放在asp.net的<header>里就会报错,放在<body>里不报错。而如果去掉这一句就放在哪里都不报错。
我的问题是
1.asp.net里的javascript放在哪里比较好。
2.为什么在<header>里要求不能有<% ... %>)?请从asp.net的页面生成的角度来解释这个要求的必然性。
Server Error in '/WebApp' 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: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:
[HttpException (0x80004005): The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).]
System.Web.UI.ControlCollection.AddAt(Int32 index, Control child) +2105879
System.Web.UI.PageTheme.SetStyleSheet() +345
System.Web.UI.Page.OnInit(EventArgs e) +2057570
System.Web.UI.Control.InitRecursive(Control namingContainer) +321
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +692
解决方案 »
- 关于服务器连接数据库
- 弹出窗口样式问题
- 对于不返回任何基表信息的 SelectCommand 不支持动态 SQL 生成
- 菜鸟又有问题了是关于server2000与asp.net的删除的一个小问题;来者有分!!!!
- 哪里有.net在access数据库里添加表和字段的教程??
- 急,请教关于ASP.NET站点的压力问题。
- 在线求解 网页打不开
- 用户控件为什么不能提交数据!求助!!!!!!!!!!!
- 这是为什么?
- 如何更改地址栏内容?现在打开的是数据库中的Word文件,可是另存为时是WebFrom1.doc,如何才能是此文件名呢?有FileName字段。
- Response.Redirect(FormsAuthentication.GetRedirectUrl(username, false))跳转失败
- 用wmrm sdk开发drm系统 如何让用户定制权限
2、不是不能有<%%>,关键是看其中是什么内容了.
------------------------------------
静态的就放在<head></head>里吧,动态的就用scriptmanage类动态生成注册.
2.为什么在 <header> 里要求不能有 <% ... %> )?请从asp.net的页面生成的角度来解释这个要求的必然性。
var a=" <%=Request.ApplicationPath %> ";
Request.ApplicationPath???明明是服务端的语言啊.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default11.aspx.cs" Inherits="Default11" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<script type="text/javascript">
document.title="<%=Request.ApplicationPath %>";
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
-------------------------
我认为放在最靠近</body>最好,这样的避免对象未定义错误,不过W3C规范是要放在head里.
2.为什么在 <header> 里要求不能有 <% ... %> )?请从asp.net的页面生成的角度来解释这个要求的必然性。
------------------------
可以,你可能哪里搞错了.另外,W3C标准,script是不必要language属性的.
第二个问题 <% ... %> asp.net 中不提倡用吧,这个好像是从ASP过度来了
确实是有报错的。