Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 C#
sir !
I want to attach a masterpage to a default.aspx!
how I can
Posted 7-Jul-13 8:33am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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...
 

[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
Add
MasterPageFile="~/Master.master"
to the @ Page directive at the top of your code file.
 
Example (example taken from this MSDN page[^]):
<% @ 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.
  Permalink  
v3
Comments
tusharkaushik at 7-Jul-13 14:41pm
   
can u explain me in detail !
where I have to write the code !
on the default or masterpage
ProgramFOX at 8-Jul-13 2:31am
   
You should write the code on the default.aspx page.
tusharkaushik at 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
ProgramFOX at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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:
 
<%@ 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"
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 390
1 Sergey Alexandrovich Kryukov 329
2 BillWoodruff 210
3 Afzaal Ahmad Zeeshan 204
4 CPallini 185
0 OriginalGriff 5,515
1 DamithSL 4,451
2 Maciej Los 3,902
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,175


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 8 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100