4

I want to assign one master page dynamically for a pure aspx file, Anybody can tell me, how to do this?

Eduardo Molteni
  • 38,786
  • 23
  • 141
  • 206
Developer404
  • 5,716
  • 16
  • 64
  • 102

2 Answers2

6

You can override OnPreInit in your default.aspx.cs and set the master page based on some value in your querystring. Something like this:

protected override void OnPreInit(EventArgs e)
    {
        base.OnPreInit(e);
        if (Request.QueryString["Master"] == "Simple")
            MasterPageFile = "~/Masterpages/Simple.Master";
    }

EDIT: the cause of your error message might be covered by this question.

Community
  • 1
  • 1
davek
  • 22,499
  • 9
  • 75
  • 95
  • "Content controls have to be top-level controls in a content page or a nested master page that references a master page. " Ya... I already used that.. But, I got that above error msg.. Can't open it – Developer404 Oct 09 '09 at 09:13
  • I tried it already, But the following error msg occurs while occurs: Content controls have to be top-level controls in a content page or a nested master page that references a master page. System.Web.HttpException: Content controls have to be top-level controls in a content page or a nested master page that references a master page. – Developer404 Oct 09 '09 at 09:14
0

I Left the ContentPlaceholder to add on it.. Actually , I tried to assign master page without using ContentPlaceHolder.. Now, I realised that, atleast one ContentPlaceholder should be there temporarily, even though we will change the master page dynamically...

Developer404
  • 5,716
  • 16
  • 64
  • 102