1

试图了解MasterPage渲染后如何PageHtmlTextOutput 中已经存在的内容?

ASP.NET,首先调用Page.Render,然后Page渲染它的子控件,MasterPage理论上是页面的“子控件”。如果是这样,那么在 MasterPage.Render 完成后如何包含 Page 的所有其他子控件的输出?Master.Render 如何“调用”页面本身及其子控件的渲染?

示例:母版页:

<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MAIN.master.cs" Inherits="Demo.MAIN" %>

<!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></title>
    <asp:ContentPlaceHolder ID="head" runat="server">
    </asp:ContentPlaceHolder>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        ContentPlaceHolder - BEFORE
        <asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">

        </asp:ContentPlaceHolder>
        ContentPlaceHolder - AFTER
    </div>
    </form>
</body>
</html>
public partial class MAIN : System.Web.UI.MasterPage
{
    protected override void Render(HtmlTextWriter writer)
    {
        base.Render(writer);
        //At this point HtmlTextWriter already contains the output of all page child controls...how it's happen?
    }

页:

<%@ Page Title="" Language="C#" MasterPageFile="~/MAIN.Master" AutoEventWireup="true" CodeBehind="MAIN_PAGE.aspx.cs" Inherits="Demo.MAIN_PAGE" %>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
CONTENT
<TL:MyButton id="ServerControl" Text="btn" runat="server"/>
</asp:Content>
public partial class MAIN_PAGE : MyPage
{
    protected override void Render(HtmlTextWriter writer)
    {
        base.Render(writer);
    }
}
4

0 回答 0