Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
sir !
I want to attach a masterpage to a default.aspx!
how I can
Posted

While adding a new page by add new item option..there is a checkbox to select the master page for the page you are crating. so you can child your default page at time of creation by checking that option...


[^] You can check here and HEre...


[^]
 
Share this answer
 
Hi,

Add
C#
MasterPageFile="~/Master.master"

to the @ Page directive at the top of your code file.

Example (example taken from this MSDN page[^]):
C#
<% @ Page Language="C#" MasterPageFile="~/Master.master" Title="Content Page 1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="Main" Runat="Server">
    Main content.
</asp:Content>
    
<asp:Content ID="Content2" ContentPlaceHolderID="Footer" Runat="Server" >
    Footer content.
</asp:content>

Hope this helps.
 
Share this answer
 
v3
Comments
tusharkaushik 7-Jul-13 14:41pm    
can u explain me in detail !
where I have to write the code !
on the default or masterpage
Thomas Daniels 8-Jul-13 2:31am    
You should write the code on the default.aspx page.
tusharkaushik 8-Jul-13 3:46am    
but i wrote this code:
<asp:Content ID="Content2" ContentPlaceHolderID="Footer" Runat="Server" >
Footer content.
but when i run the website , the message displays the "content placeholders are allowed only in masterpage
Thomas Daniels 8-Jul-13 3:51am    
I've no idea about that. The most important thing is that you add MasterPageFile="~/Master.master" to the @ Page directive. Change "~/Master.master" into the path of your master page.
To create a new Page with Master Page:

While Add a new Item, A dialog Box will open to give the name to save, there one check box will be there, 'select Master Page', Check that and give ok, and another Dialog Box will open. There you need to select Master Page. & now Master Page will be selected.

To Add the Master Page with Existing Page:

VB
<%@ Page Language="C#" MasterPageFile="Masterpage.master" AutoEventWireup="true"
    CodeFile="default.aspx.cs" Title="Untitled Page" %>


This code will be available in the design page of default.aspx, (First Line of the Page)

you should add
MasterPageFile="Masterpage.master"
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900