Click here to Skip to main content
15,915,093 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys,

I need your help again that I couldn't find a solution about how to add a master page to an existing web page.

Could you help me pls?

Awaiting somebody reply.

Regards

Haluk
Posted

You have to declare the master page that should be used in your page directive like
HTML
<% @ Page Language="VB" MasterPageFile="~/Master.master" Title="Content Page 1" %>


But that most probably won't be enough since using a master page also requires defining the Content controls in your existing page. You should have a look e.g. at

http://msdn.microsoft.com/en-us/library/wtxbf3hh(v=vs.100).aspx#Y346[^]
 
Share this answer
 
v3
Add this property in your page directive.
C#
<%@ Page MasterPageFile="myMaster.master" %>


The you need to remove everything apart from the contents of the form tag.


XML
<asp:Content id="ContentPlaceholder2" runat="server" ContentPlaceholderId="MasterID">

 paste content of form tag

</asp:Content>


ContentPlaceholderId id must be id of ContentPlaceHolderfrom master page.
 
Share this answer
 
v2

If you have not created the master page when you were creating the page or previously created page. That case you have to do it manually

First you have add the following code as follows
1. Mention the Master Page File path in the Page Directory

ASP.NET
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default1.aspx.cs" Inherits="Default1" Title="Untitled Page" %>


2. Then add the content place holder code next to the page declarative code.

ASP.NET
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"> <asp:Content>


3. Then remove HTML tags from
HTML
<HTML>up to <FORM>tag
Be sure that you have not runat=server in form tag or delete FORM tag from that page.why?because master page form tag contain the runat=server attribute.
so you should not have the another form tag in the child form with runat=server.
This way you can make the existing page to the master paged one.
 
Share this answer
 
Comments
haluk_78 28-Aug-12 7:15am    
Slide Master Page:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="SlideMasterPage.master.cs" Inherits="depo.SlideMasterPage" Debug="true" %>
<%@ Register assembly="MBMenus" namespace="MBMenus" tagprefix="mb" %>

<!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 id="Head1" runat="server">
</head>
<body
<form id="form1" runat="server">
<table style="width: 100%;">
<tr>
<td>
<asp:ScriptManager ID="ScriptManager1" runat="server">

<mb:SlideMenu ID="SlideMenu1" runat="server" Height="38px" Skin="Red">

<asp:contentplaceholder id="Main" runat="server" EnableViewState="true" />
</td>
</tr>
</table>
</form>
</body>
</html>


KasaEkle.aspx :

<%@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/SlideMasterPage.Master" CodeBehind="KasaEkleEski.aspx.cs" Inherits="depo.KasaEkle" %>

<%@ Register assembly="DevExpress.Web.ASPxEditors.v11.2, Version=11.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxEditors" tagprefix="dx" %>
<%@ Register assembly="DevExpress.Web.ASPxGridView.v11.2, Version=11.2.5.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxGridView" tagprefix="dx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="Main" runat="server">
<table class="style1">
<tr>
<td class="style4" style="border-style: groove">
<asp:Label ID="Label1" runat="server" Text="Giriş Tarihi">
</td>
<td class="style3" style="border-style: groove">
<dx:ASPxDateEdit ID="dtGirisTarihi" runat="server" Height="18px" Width="186px">

</td>
<td class="style5">
 </td>
<td class="style6" style="border-style: groove">
<asp:Label ID="Label4" runat="server" Text="Depo Seç">
</td>
<td class="style7" style="border-style: groove">
<asp:DropDownList ID="drpDepo" runat="server" Height="16px" TabIndex="2"
Width="183px">

</td>
<td>
 </td>
<td>
 </td>
<td>
 </td>
</tr>
<tr>
<td class="style4" style="border-style: groove">
<asp:Label ID="Label3" runat="server" Text="Kasa ID">
</td>
<td class="style3" style="border-style: groove">
<asp:TextBox ID="txtKasaID" runat="server" Height="21px" TabIndex="3"
Width="132px">
</td>
<td class="style5">
 </td>
<td class="style6" style="border-style: groove">
<asp:Label ID="Label5" runat="server" Text="Durum">
</td>
<td class="style7" style="border-style: groove">
<asp:DropDownList ID="drpDurum" runat="server" Height="16px" TabIndex="4"
Width="183px">
<asp:ListItem>ON WATER
<asp:ListItem>STOCK

</td>
<td>
 </td>
<td>
 </td>
<td>
 </td>
</tr>
<tr>
<td class="

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