必须从母版页调用内容页面功能.如果需要更多数据,请告诉我.
MasterPage.master.cs看起来像
protected void Required_Function(object sender, EventArgs e)
{
// call Update_Content_Page() from content page
}
Run Code Online (Sandbox Code Playgroud)
Default.aspx看起来像
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="contentPlaceHolder" Runat="Server">
<asp:Label ID="Label1" runat="server" Text="Label">Hello people!</asp:Label>
</asp:Content>
Run Code Online (Sandbox Code Playgroud)
Default.aspx.cs看起来像
using…
public partial class _Default : System.Web.UI.Page
{
protected void Update_Content_Page()
{
Label1.Text=”Hello world”;
}
}
Run Code Online (Sandbox Code Playgroud)
你可以尝试这样..不完全但会帮助你.....
您可以从基类继承页面.然后,您可以在基类中创建一个虚拟方法,该方法将在您的页面中被覆盖.然后,您可以从主页面调用该虚拟方法,如下所示 -
(cphPage.Page as PageBase).YourMethod();
Run Code Online (Sandbox Code Playgroud)
这cphPage是ContentPlaceHolder您的母版页中的ID .PageBase是包含该YourMethod方法的基类.