Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 03, 2011 08:46 AM by dodoji
Apr 08, 2008 08:13 AM|LINK
I have created a number of web forms for my website and only recently created a master page.
How can i attach that master page to my existing web forms?
Apr 08, 2008 09:34 AM|LINK
Well you have to do it by hand. You could try a very complicated Find-Replace. But my guess is that you will get more errors then results.
Start by creating a page that has a masterpage attached and look at its format. Compare your old pages with the new.
You really can't do it without redoing it all.
But hey , this is a chance for you to do some cleaning in you code. I went through that masterpage descovery a while back, and like you I took it one page at a time. I also got ride of all my spagetti code at the same time. It will be like spring cleaning.
Apr 08, 2008 10:41 AM|LINK
U can try this,
2) Try to allocate the essential codes below in all of your pages that you want to inherit from the master page. ( if you are using code behind file, the following line just suits ur scenario )
( put all <script runat="server"> , <html>, <head>, <body> ...etc. over here )
Apr 10, 2008 03:28 AM|LINK
The master page looks very similar to an ASPX file, but
1. The master page will have a .master
extension instead of a .aspx extension,
2. The master page uses an @ Master directive instead of an @ Page directive at the top.
3. The master pages defines the <html>, <head>, <body >, and <form>, tags.
4. The master page includes a new control, the ContentPlaceHolder control also appears in our master page. You can have one or more ContentPlaceHolder controls in a master page. ContentPlaceHolder controls are where we want our
ASPX web forms to place their content.
So the master page will should be like this:
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="Menu_Cases_Cases_remove_MasterPage" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<form id="form1" runat="server">
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
If you want to add a new ASPX web form to a project and associate the web form with a master page. You should:
1. Place a MasterPageFile attribute in the @ Page directive for the web form. The attribute points to the .master file you’ve selected.
2. The content place only have the @page directive and the content controls, but not the <html>, <head>, <body >, and <form>, tags.
2. The content page only contains markup inside of Content controls
3. You should make sure each Content control in a content page maps to exactly one of the ContentPlaceHolder controls in the Master Page
So , the content control should be like this:
<%@ Page Language="C#" MasterPageFile="~/Menu/Cases/Cases/remove/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Menu_Cases_Cases_remove_Default" Title="Untitled Page" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" />
You can read more fromt the below links:
Hope it helps.
Apr 10, 2008 11:28 AM|LINK
remove all html head body and form tag
and replace the form container with
for further reply me
Apr 10, 2008 11:48 AM|LINK
Just use the following code…
<%@ Page Language="C#" MasterPageFile="~/ MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Title="Untitled Page" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1"
copy existing contrls here with out body tag
Feb 03, 2011 08:46 AM|LINK
Hey all, I went through all the replies over here. I am quite impressed with all the replies given here. But I am bit confused as well. Actually I am in programming recently only so I am learning things. I know this is quite a very old post but when I went
through it I thought of thanking all who have given such clear answers. And I was able to grasp a lot of things from here.