Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Changing Master Pages Dynamically in asp.net

Changing Master Pages Dynamically in asp.net

Scheduled Pinned Locked Moved ASP.NET
helpcsharpasp-netcomdesign
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chohanpk
    wrote on last edited by
    #1

    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

    S 1 Reply Last reply
    0
    • C chohanpk

      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

      S Offline
      S Offline
      szukuro
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups