How to add master page to already created webform?

早过忘川 提交于 2019-12-10 13:44:01

问题


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.


回答1:


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.




回答2:


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




回答3:


you can add the content holder tag in master page. So when you add 'MasterPageFile="~/Site.Master"' then you able to add content of other pages.



来源:https://stackoverflow.com/questions/5549638/how-to-add-master-page-to-already-created-webform

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!