Changing Master Pages Dynamically in asp.net
-
i wana do "Changing Master Pages Dynamically in asp.net". one of my masters page code is public partial class MasterPage : System.Web.UI.MasterPage { protected void Page_Load(object sender, EventArgs e) { } protected void LinkButton1_Click(object sender, EventArgs e) { public partial class MasterPage2_master } } but in linkbuttons control code error comes .and i m doing this from the tutorial "http://www.exforsys.com/content/view/1627/354/1/0/" can anyone check this tutorial and tel me the problem.
Chohan
-
i wana do "Changing Master Pages Dynamically in asp.net". one of my masters page code is public partial class MasterPage : System.Web.UI.MasterPage { protected void Page_Load(object sender, EventArgs e) { } protected void LinkButton1_Click(object sender, EventArgs e) { public partial class MasterPage2_master } } but in linkbuttons control code error comes .and i m doing this from the tutorial "http://www.exforsys.com/content/view/1627/354/1/0/" can anyone check this tutorial and tel me the problem.
Chohan
The tutorial is bugged in some places, especially when writing the LinkButton_Click event handler. So here's what you have to do: 1. Add two master pages to your website, for example MasterPage1.master and MasterPage2.master. Edit them a you like, but make sure they contain the same number of ContentPlaceHolders. 2. Add a webform, for example Default.aspx, and make sure "Select master page" chechkbox is clicked. 3. When asked for the master page, select one from the earlier created ones. 4. Add two LinkButtons (or regular Buttons) to Default.aspx. Set the Text property as you like, and hook them up with Click event handlers. 5. In one of the Click event handlers write the following: Session["Master"] = "~/MasterPage1.master"; Response.Redirect(Request.Url.ToString()); while in the other change "~/MasterPage1.master" to "~/MasterPage2.master". 6. Add the following to the page: protected void Page_PreInit(object sender, EventArgs e) { if (Session["Master"] != null) this.MasterPageFile = (string)Session["Master"]; } Now run the web site, and test the functionality by clicking the LinkButtons.