Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

c# - How to call content Page function from Master Page

It is necessary to call content Page function from Master Page. Please let me know if more data needed.

MasterPage.master.cs looks like

 protected void Required_Function(object sender, EventArgs e)
 {
    // call Update_Content_Page() from content page 
 }

Default.aspx looks like

<%@ 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 looks like

using…
public partial class _Default : System.Web.UI.Page
{ 
    protected void Update_Content_Page()
    {
        Label1.Text=”Hello world”;
    }
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

you can try like this.. not exactly but will helps you.....

You can inherit your page from a base class. Then you can create a virtual method in your base class which will get overridden in your page. You can then call that virtual method from the master page like this -

(cphPage.Page as PageBase).YourMethod();

Here, cphPage is the ID of the ContentPlaceHolder in your master page. PageBase is the base class containing the YourMethod method.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...