试图理解在MasterPage
渲染之后,HtmlTextOutput中是否已存在Page
的内容?
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);
}
}