Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add master page to already created webform?

I have a asp.net webform application. Now I have to add master page in this application, but I don’t know how to merge or add new created master page with old webforms? How to handle html in webforms like <head> , <body> ? Any link in this regard will be helpful.

like image 678
jams Avatar asked Apr 05 '11 09:04

jams


2 Answers

1- Define the fixed elements in your design, and put them inside the newly created master page

2- Define the dynamic ones, and add asp:ContentPlaceHolder for them ( most commonly one for HEAD, one for main content in your BODY , and one for side content "if applicable")

<asp:ContentPlaceHolder ID="CphHead" runat="server">
</asp:ContentPlaceHolder>

3- In your pages, add MasterPageFile="~/MASTER_PAGE_PATH" inside the Page directive.

4- Add asp:Content sections inside your pages which will hold the dynamic content in your pages, and don't forget to reference the correct ContentPlaceholder ID.

    <asp:Content ID="HeadContent" ContentPlaceHolderID="CphHead" runat="server">

       // Your content goes here...

    </asp:Content>

5- Copy your page content inside these asp:content sections, and BOOOOM....you are done.

like image 89
Mohammed Swillam Avatar answered Sep 27 '22 22:09

Mohammed Swillam


at the top of the new page in the '<%@ page @>' tag add 'MasterPageFile="~/Site.Master"' then add the needed placeholders

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">

</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

</asp:Content>

of course modify these to the names you are using

like image 43
gen Avatar answered Sep 27 '22 22:09

gen