The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).问题的解决方法。
源码如下:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Welcome.master.cs" Inherits="MasterPage_Welcome" %>
<%@ Register src="../UserControl/Level1_.ascx" tagname="Level1_" tagprefix="uc1" %>
<%@ Register src="../UserControl/Header.ascx" tagname="Header" tagprefix="uc2" %>
<%@ Register src="../UserControl/Footer.ascx" tagname="Footer" tagprefix="uc3" %>
<!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 id="Head1" runat="server">
<title>明芳管理系统 - <%= Page.Title %></title>
<link href="~/Styles/MainStyle.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../Scripts/JQuery/jquery-1.8.0.min.js"></script>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
<script type="text/javascript">
$(document).ready(function () {
if ($('#<%#lingjian.ClientID%>').val() == "4")
$(".main-header").css("height", "75px");
else if ($('#<%#lingjian.ClientID%>').val() != "3")
$(".main-header-inner").css("line-height", "50px");
});
</script>
</head>
<body>
<ext:ResourceManager ID="ResourceManager2" runat="server" DirectMethodNamespace="CompanyX" />
<form id="form1" runat="server">
<asp:HiddenField runat="server" ID="lingjian" />
<div class="main-header">
<div class="main-header-inner">
<ul class="main-header-menu" runat="server" id="custommenu">
<uc1:Level1_ ID="Level1_1" runat="server" />
<%--<li><a href="PingBan.aspx">平板调库</a></li>--%>
<%--<li><a href="RawProcess.aspx">原材收料</a></li>--%>
<%--<li><a href="ShengChan.aspx">生产管理</a></li>--%>
<%--<li><a href="StockPro.aspx">零件库存</a></li>--%>
<%--<li><a href="RawList.aspx">原材库存</a></li>--%>
<%--<li><a href="ProList.aspx">交货记录</a></li>--%>
<%--<li><a href="StockDetail.aspx">库存信息</a></li>--%>
<%--<li><a href="Profile.aspx">修改资料</a></li>
<li><a href="../Process/StatisticReport.aspx">报表</a></li>--%>
<%
Response.Write(Convert.ToString(Session["Authorities"]));
%>
<uc2:Header ID="Header1" runat="server" />
</ul>
</div>
</div>
<div class="main-body">
<div class="main-body-inner">
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
<div class="clear"></div>
</div>
<div class="main-footer">
<div class="main-footer-inner">
<uc3:Footer ID="Footer1" runat="server" />
</div>
</div>
</form>
</body>
</html>
当添加这句代码时出现上述错误:<ext:ResourceManager ID="ResourceManager2" runat="server" DirectMethodNamespace="CompanyX" />
解决方法:
1. 将<%= 换为<%#
2. 在.asp或模板页中的Page_Load事件中添加如下代码