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.
Best regards,
Denis Radoiu
---------------------------------
If you found this useful, please mark it as an answer. Thank you.
td><asp:ContentPlaceHolder
ID="aad"
runat="server"
/> ( this is where you want your contents of all of your pages that using masterpage will be )
</td>
</
form>
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 )
The master page looks very similar to an ASPX file, but
1. The master page will have a .master file
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.
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.
Cassy01
Member
39 Points
165 Posts
Master Pages on Existing Web Forms
Apr 08, 2008 08:13 AM|LINK
Hi,
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?
Denis Chioch...
Participant
932 Points
198 Posts
Re: Master Pages on 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.
Denis Radoiu
---------------------------------
If you found this useful, please mark it as an answer. Thank you.
canalso
Member
417 Points
288 Posts
Re: Master Pages on Existing Web Forms
Apr 08, 2008 10:41 AM|LINK
U can try this,
1) Create a master page and make sure the following lines are exist.<%
@ Master Language="VB" CodeFile="components/loginmain.master.vb" Inherits="MasterPageFiles_LoginMain" ClassName="MasterCN_LoginMain"%><
form id="frm_login" runat="server">....
<
td><asp:ContentPlaceHolder ID="aad" runat="server" /> ( this is where you want your contents of all of your pages that using masterpage will be ) </td></
form>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 )
<%@ Page Language="VB" Inherits="class_datasetcashstatement" src="components/datasetcashstatement.vb" ContentType="text/html; charset=utf-8" MasterPageFile="MasterPage2.master" EnableSessionState="True" EnableEventValidation="false" AutoEventWireup="false" Title="Cash Statement Content Page" %><%
@ MasterType VirtualPath="MasterPage2.master" %><
asp:Content ID="First" ContentPlaceHolderID="aad" Runat="Server">( put all <script runat="server"> , <html>, <head>, <body> ...etc. over here )
</
asp:Content>[:)]
Amanda Wang ...
All-Star
30008 Points
3104 Posts
Re: Master Pages on Existing Web Forms
Apr 10, 2008 03:28 AM|LINK
Hi,
The master page looks very similar to an ASPX file, but
1. The master page will have a .master file 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">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<table class="style1">
<tr>
<td colspan=2>
Head</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</td>
</tr>
</table>
</form>
</body>
</html>
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" />
</asp:Content>
You can read more fromt the below links:
Hope it helps.
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
shayas
Participant
1636 Points
365 Posts
Re: Master Pages on Existing Web Forms
Apr 10, 2008 11:28 AM|LINK
<%
@ Page Language="VB" MasterPageFile="[Master Page Path]" AutoEventWireup="false" CodeFile="[codefile]" Inherits="[class]" Title="[title]" %>remove all html head body and form tag
and replace the form container with
<
asp:Content ID="[contentplace holderid]" ContentPlaceHolderID="[contentplace holderidmaster]" runat="Server"></
asp:Content>for further reply me
Application Developer,Sharjah Municipality, UAE
Please remember to mark as answers if this helps
thirumaran00...
Star
8172 Points
1722 Posts
Re: Master Pages on Existing Web Forms
Apr 10, 2008 11:48 AM|LINK
Hi friend
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
</asp:Content>
With Friendly,
Thirumaran
dodoji
Member
6 Points
3 Posts
Re: Master Pages on Existing Web Forms
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.