【发布时间】:2012-10-16 17:32:42
【问题描述】:
我有两个母版页和一个内容页。在我的本地机器上,这段代码可以工作,但是一旦我上传到服务器,我得到了以下错误:
编译错误 说明:在编译服务此请求所需的资源期间发生错误。请查看以下特定错误详细信息并适当修改您的源代码。
编译器错误消息:CS1061:“System.Web.UI.MasterPage”不包含“DivWidth”的定义,并且没有接受“System.Web.UI.MasterPage”类型的第一个参数的扩展方法“DivWidth”可以找到(您是否缺少 using 指令或程序集引用?)
来源错误:
第 84 行:
第 85 行:
第 86 行:this.Master.Master.DivWidth = 955;
第 87 行:SimpleElementCollection restrictedIds = new SimpleElementCollection();
第 88 行:restrictedIds.Add(new SimpleElement(priceModifierPriceTypeId));
源文件:c:\Inetpub\testsite\shop\Default.aspx.cs 行:86
基本主页代码:
public partial class global : System.Web.UI.MasterPage
{
public int DivWidth { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
SetBodyClass();
if (DivWidth < 1)
{
DivWidth = 768;
}
}
基础母版页aspx:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="global.master.cs" Inherits="global" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US" dir="ltr">
<head id="Head1" runat="server" dir="ltr" lang="en-us" profile="http://dublincore.org/documents/dcq-html/">
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>page title</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="content-type" content="en-US" />
<meta http-equiv="content-language" content="en-us" />
<link rel="Bookmark" href="#content" title="Page Content" type="text/html" />
<link rel="Bookmark" href="#primary-navigation" title="Site Navigation" type="text/html" />
<link href="css/screen/global.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/print/print.css" rel="stylesheet" type="text/css" media="print" />
<script src="<%=ResolveUrl("~/javascript/jquery-1.2.6.min.js")%>" type="text/javascript"></script>
<script src="<%=ResolveUrl("~/javascript/jquery.clearonfocus.js")%>" type="text/javascript"></script>
<script src="<%=ResolveUrl("~/javascript/modalControl.js")%>" type="text/javascript"></script>
<asp:ContentPlaceHolder ID="headPlaceholder" runat="server" />
<!--[if IE]><link href="css/screen/ie/ie.css" rel="stylesheet" type="text/css" media="screen" /><![endif]-->
<!--[if IE 6]><link href="css/screen/ie/ie-6.css" rel="stylesheet" type="text/css" media="screen" /><![endif]-->
]
</head>
<body id="Body" runat="server">
<div id="main">
<div id="main-inner">
<div id="content" style="width:<%=DivWidth%>px;"><div id="content-top"></div><div class="content-inner"><asp:ContentPlaceHolder ID="contentPlaceHolder" runat="server" /><asp:ContentPlaceHolder ID="BelowLeftRightMainContent" runat="server" /></div> </div>
</body>
</html>
第二个母版页:
<%@ Master Language="C#" MasterPageFile="~/global.master" AutoEventWireup="false" CodeFile="shopFalcon.master.cs" Inherits="shopFalcon" %>
<%@ Register TagPrefix="FALCON" TagName="FeatureProducts" Src="~/FalconShopRightHand.ascx" %>
<%@ Register TagPrefix="FALCON" TagName="ProductSearch" Src="~/FalconProductSearch.ascx" %>
<%@ Register TagPrefix="FALCON" TagName="AbuseText" Src="~/FalconAbuseLinkDisplay.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="headPlaceholder" Runat="Server">
</asp:Content>
除了后面的空代码,后面的代码没有任何内容
我的内容页面:
<%@ Page Language="C#" MasterPageFile="~/shop.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="shopFalcon_Default" Title="Shop Homepage" %>
<%@ MasterType VirtualPath="~/shop.master"%>
<asp:Content ID="Content7" ContentPlaceHolderID="leftColPlaceHolder" Runat="Server">
<asp:Image ID="Image1" runat="server" ImageAlign="Right" ImageUrl="~/images/Free+Shipping+01.jpg" CssClass="img"/>
<h1>Shop Anytime, anywhere. </h1>
<div id="shopByBrandDiv">
</asp:Content>
我的代码:
protected void Page_Load(object sender, EventArgs e)
{
this.Master.Master.DivWidth = 955;
}
这同样适用于使用内置 Web 服务器的 Visual Studio,但部署到运行 IIS6 的生产服务器时,我得到了上述错误。
有什么想法吗?
【问题讨论】:
-
可能编译不正确,尝试完全重新编译您的页面。
-
@Aristos 它似乎可以编译,我在 web.config 中放了两个空格然后删除它们,这通常会强制重新编译。
-
hm,IMO 这应该永远不会起作用,因为您需要从 MasterPage 转换到您自己的类 ((global)this.Master.Master).DivWidth = 955;
标签: c# asp.net master-pages