Sunday, January 23, 2011

How to apply a Master Page to Existing Webpage OR Easily convert An Existing Web Form to a Web Content Form(with a Master Page)

Its our common behavior to change our web site on sparkle of our eyes. And for adding the banner or common things in each page is really difficult to perform. Concept of Master Page has handed over the freedom to us. For master page is the natural way to develop each web pages as the content page of the Master One. But We can ad our already
designed web page as the content page of the Master Page. Different way to say, we can apply Master Page o an existing Web page by following some steps.To convert from a Web Form to Web Content Form, all of the changes will occur in the Web Form’s aspx page.
just follow the following steps:

1.Create a Master Page
2.Apply Master Page via design mode in existing wen page
3.Copy over the Content Containers
4.In your Web Form, move Web Controls and information into the proper Content Containers.

Suppose, we have a web page named frmAddTask.aspx, we want to add the Master Page to this page. A s the part of above steps, we create the Master Page.
Then we need to go to the Design mode of our Web page frmAddTask.aspx, making the right-click we have to choose the properties for this page. From the properties, we select the Master Page option and show the Master Page we have created for this web page. Then in the code of the web page a small but vast change will be effected at the top line of its code view.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="frmAddTask.aspx.cs" Inherits="SMS_IB_Support_tools.UI.frmAddTask" MasterPageFile="~/UI/SMS-IB.Master" %>


Now, the second and final step is to put items into the correct content boxes. The easiest and more error free to do this is to create a new blank Web Content Form, copy the content boxes from the Web Content Page, and paste them into our original Web Form. So right click the Master page in the Solution Explorer and select Add Content Page. Our example will output:

<%@ Page Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" Title="Untitled Page" %>





Copy lines 2-5 above and paste them into frmAddTask.aspx right below the “<%@ Page” directive. The ContentPlaceHolderID called ContentPlaceHolder1 will hold all the information between
in our "frmAddTask.aspx. The rest of the information below can be deleted.
We will must have to follow that, in the existing Web Page FORM tag is appeared. And in the Master Page also the
tag is available. Both of them can not be applied at the same time. So we will have to awakened to use the FORM tag of the master page only. Otherwise, we will get error message.

No comments: