Click here to Skip to main content
15,884,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys,

In my ASP.net project i have two folder inside root folder:

1- Admin folder: it has Admin MasterPage and some pages.

2- Member folder: it has Member MasterPage and some pages one is called Comments.aspx


in some case, when i go to Comments.aspx by:

Server.Transfer("~/Members/MemberComments.aspx");



i want to change its MasterPage from Member MasterPage to Admin MasterPage by:

C#
protected void Page_PreInit(object sender, EventArgs e)
{
    this.MasterPageFile = "~/Admins/AdminMaster.master";
}




but it give me error that: Error executing child request.


I think that because every MasterPage in different folder.

Then, is there some solution please?
Posted
Updated 22-Apr-11 18:55pm
v3

You need to use the Page_PreInit method of the content page. This is the place where Master page can be set dynamically.

Have a look at the exact dicsussion and steps[^] here.
 
Share this answer
 
v2
Comments
Sandeep Mewara 23-Apr-11 0:54am    
?
MrLonely_2 23-Apr-11 0:55am    
i used Page_PreInit method and the problem still
Sandeep Mewara 23-Apr-11 0:57am    
What problem? If you try to be elaborate and stop talking in telegrams it would help. It would be difficult if you expect me to put all the pieces together.

MrLonely_2 23-Apr-11 0:59am    
thank u, please do not answer me....... i do not understand u
Sandeep Mewara 23-Apr-11 1:05am    
Sure!
make two master pages named Dynamic1.master and Dynamic2.master.

and then use profile properties to get access the master pages.
XML
<configuration>
<system.web>
<profile>
<properties>
<add
name="MasterPageFile"
defaultValue="Dynamic1.master" />
</properties>
</profile>
</system.web>
</configuration>



then make a content page for dynamic1.master like this.

XML
<asp:Content
ID="Content1"
ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
Select a Master Page:
<ul >
<li>
<a href="DynamicContent.aspx?master=Dynamic1">Dynamic Master 1</a>
</li>
<li>
<a href="DynamicContent.aspx?master=Dynamic2">Dynamic Master 2</a>
</li>
</ul>
</asp:Content>


masterpage can only be call in preinit event.

C#
protected void Page_PreInit(object sender, EventArgs e)
{
if (Request["master"] != null)
{
switch (Request["master"])
{
case "Dynamic1":
Profile.MasterPageFile = "Dynamic1.master";
break;
case "Dynamic2":
Profile.MasterPageFile = "Dynamic2.master";
break;
}
}
MasterPageFile = Profile.MasterPageFile;
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900