Include master page at run time
-
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.
-
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.
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
-
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
-
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.
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
-
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
-
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?
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 helpsAll C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
-
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 helpsAll C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
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--
-
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 helpsAll C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia How to use google | Ask smart questions
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?
-
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?
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--
-
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--