How to configure MasterPage to Inherit class file - c#

I have a Master page which needs to inherit from a class (MasterPage2.cs) stored inside "App_Web_yht1mma2" folder.
In the master page, I have set the code as:
<%# Master Language="C#" AutoEventWireup="true" Inherits="MasterPage2,App_Web_yht1mma2" %>
When I debug this page, I receive the following error:
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load the assembly 'App_Web_yht1mma2'. Make sure that it is compiled before accessing the page.
Source Error:
Line 1: <%# Master Language="C#" AutoEventWireup="true" Inherits="MasterPage2,App_Web_yht1mma2" %>
Line 2:
Line 3:
Source File: /MasterPage.master Line: 1
Kindly advise me on how to correct this error.

Thank you for your help but I managed to figure it out through assistance from a friend.
<%# Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage2" %>
or
<%# Master Language="C#" AutoEventWireup="true" CodeBehind="MainMasterPageWeb.Master.cs"
Inherits="App_Web_yht1mma2.MasterPage2" %>
Both ways are possible solutions

Related

ASP.NET controls not recognised in code behind

I am getting the
"The name 'ASP.net control' does not exist in the current context"
Error message. Guys, can you please help me find out the cause of this and how to remedy it!
Am I missing something here??
<%# Page Title="Amatola Water Activities" Language="C#" MasterPageFile="~/Site.Master"
AutoEventWireup="true" CodeFile="~/Default.aspx.cs"
Inherits="AWActivitiesWeb2.Default" %>
There could be several reasons behind this error, Looking at the <%# Page %> directive that you shared, you have specified the attribute as CodeFile="~/Default.aspx.cs" Which might be causing this issue because if you specify a CodeFile attribute, the designer.cs file does not regenerates itself. Either you manually specify each control you add into the designer.cs file or you should change the CodeFile attribute to a CodeBehind attribute.
The other issue could be with the control itself, if you won't specify runat="server" on the attribute then you won't get its reference in the Code Behind.
So, Modify your page directive with this line:
<%# Page Title="Amatola Water Activities" Language="C#"
MasterPageFile="~/Site.Master" AutoEventWireup="true"
CodeBehind="~/Default.aspx.cs" Inherits="AWActivitiesWeb2.Default" %>

Could not load type 'BestPricingEngine.Main'

I have searched through Stackoverflow, Google, and tried different configurations like CodeFile rather than CodeBehind. The error changes slightly but still get it, really stuck on this one. Any help will be appreciated. The exact error is below, my code for that error is below that.
Server Error in '/' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load type 'BestPricingEngine.Main'.
Source Error:
Line 1: <%# Page Title="Import FBA Orders" Language="C#" AutoEventWireup="true" MasterPageFile="~/MasterPages/MasterPage.Master" CodeBehind="ImportFBAOrders.cs" Inherits="BestPricingEngine.Main" %>
Line 2: <%# Register src="ImportFBAOrders.ascx" tagname="ImportFBAOrders" tagprefix="ucImportFBAOrders"%>
Line 3:
Source File: /Pages/ImportFBAOrders/ImportFBAOrders.aspx Line: 1
<%# Page Title="Import FBA Orders" Language="C#" AutoEventWireup="true" MasterPageFile="~/MasterPages/MasterPage.Master" CodeBehind="ImportFBAOrders.cs" Inherits="BestPricingEngine.Main" %>
<%# Register src="ImportFBAOrders.ascx" tagname="ImportFBAOrders" tagprefix="ucImportFBAOrders"%>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="server"></asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cpSidebar" Runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="cpMainContent" runat="server">
<ucImportFBAOrders:ImportFBAOrders ID="importFBAOrders" runat="server" />
</asp:Content>
There should not be a period in your BestPricingEngine.Main. The Inherits attribute is normally used in the markup to reference the code-behind of that page.
In other words, looking at this code, I would assume your Inherits attribute should be named after that page's class, which is usually the path of the code-behind file delimited by underscores, and excluding the file extension.
EDIT
Change Inherits="BestPricingEngine.Main" to Inherits="BestPricingEngine.Pages"

Can I use an asp.net master page in vb for an application written in c#?

I have a website (asp.net 4) with 49 pages. The website is in vb.
But I added a forum (and called it "knowledgbase"), so it's like ... company.com/knowledgebase/ ... I configured the forum as a separate application in IIS7, and it's written in c#.
Is it possible to use one of my vb master pages in the c# forum? Or would I have to create an entirely separate c# master page?
Edit:
Basically, in the knowledgebase/default.aspx file, there's this:
<%# Page Language="C#" AutoEventWireup="true" ValidateRequest="false"
Inherits="YAF.ForumPageBase" culture="auto" uiculture="auto" %>
<%# Register TagPrefix="YAF" Assembly="YAF" Namespace="YAF" %>
<script runat="server">
I tried doing this:
<%# Page Language="C#" AutoEventWireup="true" ValidateRequest="false"
Inherits="YAF.ForumPageBase" culture="auto" uiculture="auto"
MasterPageFile="~/homepage.Master" %>
<%# Register TagPrefix="YAF" Assembly="YAF" Namespace="YAF" %>
<script runat="server">
But of course ... the page language says "c#" and the master page is written in vb. So the result was this (as expected):
Server Error in '/knowledgebase' Application.
Parser Error
Description: An error occurred during the parsing of a resource required to service
this request. Please review the following specific parse error details and modify your
source file appropriately.
Parser Error Message: The 'masterpagefile' attribute is not supported by the
'register' directive.

Creating a web form using master page

I have been doing this for hours and it keep coming out the same error. I don't know why ! I managed to create the first webform for masterpage. Somehow , subsequence webforms are getting the same error.
This is the webform i had created:
<%# Page Title="" Language="C#" MasterPageFile="~/EIDShopMain.Master" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="mainWebsite_EID_Shop_.WebForm3" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
</asp:Content>
When i want to view it in browser:
Server Error in '/' Application.
Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load type 'mainWebsite_EID_Shop_.Global'.
Source Error:
Line 1: <%# Application Codebehind="Global.asax.cs" Inherits="mainWebsite_EID_Shop_.Global" Language="C#" %>
Update: This is a ASP.Net Web Application Project.
Code-behind of WebForm3:
namespace mainWebsite_EID_Shop_
{
public partial class WebForm3 : Page
{
}
}
Can anyone explain why sometime the web form works and sometime it doesn't works.
Update2: More errors:
Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Could not load type 'mainWebsite_EID_Shop_.EIDShopMain'.
Source Error:
Line 1: <%# Master Language="C#" AutoEventWireup="true" CodeBehind="EIDShopMain.master.cs" Inherits="mainWebsite_EID_Shop_.EIDShopMain" %>
Line 2:
Line 3: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">;
Your Global.asax should look like the following:
<%# Application Inherits="mainWebsite_EID_Shop_.Global" %>
and Global.asax.cs:
namespace mainWebsite_EID_Shop_
{
public class Global
{
}
}

Parser Error Message: The file '/TestSite/Default.aspx.cs' does not exist

Short story.
This site was created by a friend of mine, who did not know that much C# or asp. And was firstly created in VS 2k3. When i converted it to VS 2k8 these errors started to crop up, there was also other issues with compiling that i managed to sort out ( Seemed to be released to VS 2k8 wanted design files )
Error message gotten:
An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: The file '/TestSite/Default.aspx.cs' does not exist.
Source Error:
Line 1: <%# Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="GuildStats._Default" %>
Line 2:
Line 3: <asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="Server">
Defaults.aspx.cs
namespace GuildStats
{
public partial class _Default : System.Web.UI.Page
{
Defaults.aspx
<%# Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="GuildStats._Default" %>
Site.master.cs
namespace GuildStats
{
public partial class Site : System.Web.UI.MasterPage { }
}
Site.master
<%# Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="GuildStats.Site" %>
In Default.aspx change CodeFile to CodeBehind. You'll probably have to do the same for the Site.master.
See: CodeFile and Code-Behind
Web Site projects use CodeFile, Web Application projects use CodeBehind.
CodeFile requires the source file, it is compiled on the fly when the page is loaded, CodeBehind requires the compiled code.
My guess is that your problem was created when you changed your project type from a WebApp to a Web Site or vice-versa. If you do this, you have to manually change the directives in the existing files, new files will have the right directive automatically.

Categories

Resources