I have a master page(MyMasterPage.master) with two content place holders. I wanna show another aspx page(MyHeader.aspx) in the 1st content place holder of a content page(MyContentPage.aspx) that uses my master page.
R – show an aspx page in content tag
asp.netmaster-pages
Related Solutions
Another thing to consider is nested master pages. I have a similar design layout I'm doing in a current project, and we have a "base" master page that does all of our script includes, header and footer, and has just a single ContentPlaceHolder that represents everything between the header and footer. We then have a nested master page that uses the base master page, but adds a right "aside" column. For pages where we want the right column visible, we use the nested master page. For pages where we don't want it rendered, we use the base master page.
A strategy like this would definitely prevent your column #3 from being rendered at all (as opposed to being rendered and just being empty, which might not achieve the layout you're going for).
It looks something like this:
Base master page:
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MasterBase.Master.cs" Inherits="MasterBase" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
...
<asp:ContentPlaceHolder ID="head" runat="server" />
</head>
<body>
<form id="form1" runat="server">
<!-- HEADER -->
...
<!-- CONTENT -->
<asp:ContentPlaceHolder ID="bodyContent" runat="server" />
<!-- FOOTER -->
...
</form>
</body>
</html>
Nested Master Page
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<asp:ContentPlaceHolder ID="head" runat="server" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="bodyContent" runat="server">
<!-- CENTER COLUMN -->
<div id="centerCol">
<asp:ContentPlaceHolder ID="bodyContent" runat="server" />
</div>
<!-- RIGHT COLUMN -->
<div id="rightCol">
<asp:ContentPlaceHolder ID="rightColumn" runat="server" />
</div>
</asp:Content>
The content page load event will fire before the master page load event.
See here for full order (MSDN: Events in ASP.NET Master and Content Pages)
Copying incase link goes dead:
The following is the sequence in which events occur when a master page is merged with a content page:
- Content page PreInit event.
- Master page controls Init event.
- Content controls Init event.
- Master page Init event.
- Content page Init event.
- Content page Load event.
- Master page Load event.
- Master page controls Load event.
- Content page controls Load event.
- Content page PreRender event.
- Master page PreRender event.
- Master page controls PreRender event.
- Content page controls PreRender event.
- Master page controls Unload event.
- Content page controls Unload event.
- Master page Unload event.
- Content page Unload event.
Best Answer
You should be using user controls for reusable components of a pages. Create a Header.ascx file instead of a .aspx. You can then drag that into your ContentPlaceHolder from the solution explorer when in design mode.
http://msdn.microsoft.com/en-us/library/y6wb1a0e.aspx