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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. Include master page at run time

Include master page at run time

Scheduled Pinned Locked Moved ASP.NET
help
10 Posts 4 Posters 8 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.
  • J Offline
    J Offline
    J Liang
    wrote on last edited by
    #1

    Hi, I am currently wanted to include my master page into a page that do not include master page initially. I'd tried this code, protected override void OnPreInit(EventArgs e) { this.MasterPageFile = "~/Main.master"; base.OnPreInit(e); } but run into this error Content controls have to be top-level controls in a content page or a nested master page that references a master page What I am trying to do is to include a master page into the web page during run time as I only wanted the master page to be included when certain criteria is met. I'd look around the net but still don't get it what went wrong, hope I can get some idea from here. Thanks.

    P N 2 Replies Last reply
    0
    • J J Liang

      Hi, I am currently wanted to include my master page into a page that do not include master page initially. I'd tried this code, protected override void OnPreInit(EventArgs e) { this.MasterPageFile = "~/Main.master"; base.OnPreInit(e); } but run into this error Content controls have to be top-level controls in a content page or a nested master page that references a master page What I am trying to do is to include a master page into the web page during run time as I only wanted the master page to be included when certain criteria is met. I'd look around the net but still don't get it what went wrong, hope I can get some idea from here. Thanks.

      P Offline
      P Offline
      Parwej Ahamad
      wrote on last edited by
      #2

      Can you post here .aspx code ? Please make sure, do not put any controls out side the Content place holder and set property runat server.

      Parwej Ahamad R & D with IIS 5.0/6.0

      J 1 Reply Last reply
      0
      • P Parwej Ahamad

        Can you post here .aspx code ? Please make sure, do not put any controls out side the Content place holder and set property runat server.

        Parwej Ahamad R & D with IIS 5.0/6.0

        J Offline
        J Offline
        J Liang
        wrote on last edited by
        #3

        Here's the aspx page

        ]]>

        ]]>

        E06-Employee
        
        
        
        
        
            
            
            font-size="Small">
        
        
            DataTextField="empName" HeaderText="Name" NavigateUrl="~/E0601-NewEmployee.aspx?empid={0}&update=1&compid={1}&option=employee"
            SortExpression="empName" Target="\_blank" />
        
        1 Reply Last reply
        0
        • J J Liang

          Hi, I am currently wanted to include my master page into a page that do not include master page initially. I'd tried this code, protected override void OnPreInit(EventArgs e) { this.MasterPageFile = "~/Main.master"; base.OnPreInit(e); } but run into this error Content controls have to be top-level controls in a content page or a nested master page that references a master page What I am trying to do is to include a master page into the web page during run time as I only wanted the master page to be included when certain criteria is met. I'd look around the net but still don't get it what went wrong, hope I can get some idea from here. Thanks.

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          Looks like you have some text or control placed outside asp:content tag. When you use master pages, make sure your controls and all other texts in the content page are inside the asp:content tag.

          All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

          J 1 Reply Last reply
          0
          • N N a v a n e e t h

            Looks like you have some text or control placed outside asp:content tag. When you use master pages, make sure your controls and all other texts in the content page are inside the asp:content tag.

            All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

            J Offline
            J Offline
            J Liang
            wrote on last edited by
            #5

            Ya, I read this about asp:content tag, but what I don't understand is I could not find asp:content tag in any of my page. Sorry this might sound silly, where should this asp:content tag suppose to be in? .master or .aspx?

            N 1 Reply Last reply
            0
            • J J Liang

              Ya, I read this about asp:content tag, but what I don't understand is I could not find asp:content tag in any of my page. Sorry this might sound silly, where should this asp:content tag suppose to be in? .master or .aspx?

              N Offline
              N Offline
              N a v a n e e t h
              wrote on last edited by
              #6

              It should be in a content page, not in master page. I got your problem, you are trying to change a master page dynamically in a page where master page is not at all used. Try putting your ASPX page contents into

              <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
              </asp:Content>

              . Master page should contain body, form and a content placeholder. In your content page, supply the content placeholder id to asp:content's ContentPlaceHolderID property. Hope this helps

              All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

              S J 2 Replies Last reply
              0
              • N N a v a n e e t h

                It should be in a content page, not in master page. I got your problem, you are trying to change a master page dynamically in a page where master page is not at all used. Try putting your ASPX page contents into

                <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
                </asp:Content>

                . Master page should contain body, form and a content placeholder. In your content page, supply the content placeholder id to asp:content's ContentPlaceHolderID property. Hope this helps

                All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

                S Offline
                S Offline
                sidbaruah
                wrote on last edited by
                #7

                I think it wont help, if master page is not referenced when he wants it not to contain one, then it will throw error again, coz of using content control without a master page. I dont have a solution now, gotta check that out, if i get ill let ya know..

                I was born dumb!! :laugh:Programming made me laugh:laugh:!!! --sid--

                1 Reply Last reply
                0
                • N N a v a n e e t h

                  It should be in a content page, not in master page. I got your problem, you are trying to change a master page dynamically in a page where master page is not at all used. Try putting your ASPX page contents into

                  <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
                  </asp:Content>

                  . Master page should contain body, form and a content placeholder. In your content page, supply the content placeholder id to asp:content's ContentPlaceHolderID property. Hope this helps

                  All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions

                  J Offline
                  J Offline
                  J Liang
                  wrote on last edited by
                  #8

                  I think I slowly get what you mean. The content page is where all my textboxes, buttons are. This is what I did, in my aspx page's html:

                  But I got the error when change it back to design view Content control can only be use in a content page I guess I still missing some point you trying to tell me?

                  S 1 Reply Last reply
                  0
                  • J J Liang

                    I think I slowly get what you mean. The content page is where all my textboxes, buttons are. This is what I did, in my aspx page's html:

                    But I got the error when change it back to design view Content control can only be use in a content page I guess I still missing some point you trying to tell me?

                    S Offline
                    S Offline
                    sidbaruah
                    wrote on last edited by
                    #9

                    Let me throw some light here... If you are using a master page, the contents you are using for a page must be inside the content template as you mentioned in the post.. However, you could only have a master page on a page or you dont have one.. and as you cant change the aspx design page at runtime, it is bound to throw an error... I suggest you use two different pages, one with master page and another without it, so that you could use them according to the situations you have..

                    I was born dumb!! :laugh:Programming made me laugh:laugh:!!! --sid--

                    J 1 Reply Last reply
                    0
                    • S sidbaruah

                      Let me throw some light here... If you are using a master page, the contents you are using for a page must be inside the content template as you mentioned in the post.. However, you could only have a master page on a page or you dont have one.. and as you cant change the aspx design page at runtime, it is bound to throw an error... I suggest you use two different pages, one with master page and another without it, so that you could use them according to the situations you have..

                      I was born dumb!! :laugh:Programming made me laugh:laugh:!!! --sid--

                      J Offline
                      J Offline
                      J Liang
                      wrote on last edited by
                      #10

                      Oh ok, now I know that I can't include the master page during run time. Thanks for saving from turning in circle again and again. :)

                      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