How do I solve the error 'System.Web.UI.MasterPage' does not contain a definition for
Ok, here is the thing, this works sometimes and then when I add another property or recompile it would give me an error. it turns out it is compiler issue. To get around the issue, I had to create a App_Code directory under the root and made a class. When I get the error telling me there is no DivWidth defined, I simple make a code change in the class I created and the site compiles in the proper order. It took opening a case with MS, who was not very helpful, for me to find this workaround. Hope this helps someone else who runs into this strange issue.
James Campbell
I am MCP,MCSA,MCSE,Sec + cetified. I am currently a programmer and actively looking for work. I have been programming with multiple languages since 1996. I have experience in the following: C# VB.NET LINQ ASP.NET SQL Server PHP Silverlight WPF DotNetNuke Ektron
Updated on June 04, 2022Comments
-
James Campbell almost 2 years
I have two master pages and a content page. On my local machine this code works, but once I uploaded to the server I got the following error:
Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1061: 'System.Web.UI.MasterPage' does not contain a definition for 'DivWidth' and no extension method 'DivWidth' accepting a first argument of type 'System.Web.UI.MasterPage' could be found (are you missing a using directive or an assembly reference?)
Source Error:
Line 84:
Line 85:
Line 86: this.Master.Master.DivWidth = 955; Line 87: SimpleElementCollection restrictedIds = new SimpleElementCollection(); Line 88: restrictedIds.Add(new SimpleElement(priceModifierPriceTypeId));Source File: c:\Inetpub\testsite\shop\Default.aspx.cs Line: 86
Base Masterpage cocde:
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; } }
Base Masterpage 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>
Second Master Page:
<%@ 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>
nothing in the code behind cept empty code behind
My content page:
<%@ 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>
My code behind:
protected void Page_Load(object sender, EventArgs e) { this.Master.Master.DivWidth = 955; }
Again this works in Visual Studio using the built in web server but delpoying to the production server running IIS6 I get that error stated above.
Any ideas?
-
James Campbell over 13 years@Moo-Juice Well I would assume so, as this same code works on my local. I use it in Base Masterpage aspx and set it in that code behind and my content page
-
Moo-Juice over 13 yearsSorry, but in your pasted-code I couldn't see anywhere that DivWidth actually did anything.
-
James Campbell over 13 years@Moo-Juice Look again it is set in two places and called in this line in the base masterpage.aspx <div id="content" style="width:<%=DivWidth%>px;">
-
Moo-Juice over 13 yearsYes, I saw that. What I am saying is, the property declaration itself, given the code you have given, doesn't do anything. It's just get; set;. Are you missing something you haven't pasted?
-
James Campbell over 13 years@Moo-Juice In c# 3.0 MS introduced a new syntax for a property called an auto-implemented property, which allows you to create properties without get and set accessor implementations.
-
Moo-Juice over 13 years@James, Ah I see. I didn't know that. Thanks for the information.
-
Pauli Østerø over 13 yearshm, IMO this should NEVER work since you need a cast from MasterPage to your own class ((global)this.Master.Master).DivWidth = 955;
-
James Campbell over 13 yearsIt works both ways but I have the same issue no matter with or without the cast. I declear the master type so the class knows that this.master.master is global during runtime. It also knows this.master is shop.master. Soemtimes when I try the cast I get cannot convert type global to type masterpage. So I left it this.master.master .