user153923
user153923

Reputation:

How to use MasterPage for WebPage in SubDirectory?

Parser Error or Master Page error?

Parser Error Picture

I have a website with a MasterPage in my Visual Studio 2010 project.

I have many WebForms located in SubDirectories, but for this question I will focus on the SubDirectory called /contact.

In VS2010, all of the WebForms in the /contact directory display as they are supposed to using this page directive code:

<%@ MasterPageFile="~/Site.Master" ... %>

It is my understanding that the ~/ is supposed to direct the page to the root folder.

Yet, when I go to a page in that folder, I get a Parser Error saying that the MasterPage does not exist because the page is attempting to load the MasterPage from here:

'/contact/Site.Master'

If I modify my VS2010 project so that the page directive tries to step back to the root level, the VS project give me Master Page errors.

Does not work:

<%@ MasterPageFile="../~/Site.Master" ... %>

Also does not work:

<%@ MasterPageFile="~/../Site.Master" ... %>

Master Page error

What is the trick here?

Upvotes: 0

Views: 825

Answers (1)

varun
varun

Reputation: 4650

something is probably wrong in the visualstdio at your end.

I am pretty sure what you are doing is correct.

I just tried creating an asp.net project, added a folder called contact and then dragged a default.aspx page inside it

this is code in the markup file

<%@ Page Title="Home Page" Language="C#"  MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

Here is the folder structure.

Every things works at my end. enter image description here

BTW if you were indeed trying to read masterpage from a page in contact folder and the framework somehow looks inside contact as the root then try

../Site.Master

Upvotes: 1

Related Questions