需要从Master Page中调用content Page函数。 如果需要更多数据,请告诉我。
MasterPage.master.cs 看起来像
protected void Required_Function(object sender, EventArgs e)
{
// call Update_Content_Page() from content page
}
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>
Default.aspx.cs 看起来像
using…
public partial class _Default : System.Web.UI.Page
{
protected void Update_Content_Page()
{
Label1.Text=”Hello world”;
}
}
最佳答案
你可以这样尝试..不完全但是会帮助你.....
您可以从基类继承您的页面。然后你可以在你的基类中创建一个虚拟方法,它将在你的页面中被覆盖。然后,您可以像这样从母版页调用该虚拟方法 -
(cphPage.Page as PageBase).YourMethod();
此处,cphPage
是母版页中 ContentPlaceHolder
的 ID。 PageBase
是包含 YourMethod
方法的基类。
关于c# - 如何从母版页调用内容页功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8165930/