Mike Eghtebas
asked on
set masterpage file dynamically- c#
The only way it works is when I change it manually to:
Response.Redirect("Default 2.aspx", false); //<-- have tried true also
and in the Default2.aspx.cs I have:
But the problem is Page_Preint doesn't fire.
Question: How can I change the masterPage dynamically?
Thank you.
<%@ Page Title="" Language="C#" AutoEventWireup="false" MasterPageFile="~/MasterPage.master" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
or
<%@ Page Title="" Language="C#" AutoEventWireup="false" MasterPageFile="~/MasterPage2.master" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
To do this dynamically, from the a control on the master page, I open a page using:Response.Redirect("Default
and in the Default2.aspx.cs I have:
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Page_Preint(object sender, EventArgs e)
{
MasterPage myMaster=Master as MasterPage;
Label lbl = (Label)myMaster.FindControl("lblCmdOpt");
if (lbl.Text == "f123")
{
MasterPageFile = "~//MasterPage.master";
}
else
{
MasterPageFile = "~//MasterPage2.master";
}
}
}
But the problem is Page_Preint doesn't fire.
Question: How can I change the masterPage dynamically?
Thank you.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you.
ASKER
I have AutoEventWireup="false" and also have kept MasterPageFile="~/MasterPa
Open in new window
I added breaks at line 3 and 9 to see if the code is firing.
Line 3 is firing when the application first lunched.
But although Response.Redirect("Default
Question: What else I should do for the line 9 fires?
Thank you,
Mike