Asp.net C # homepage access method

How do I access the public methods of the homepage from a child page?

UserMaster.master.vb

Public Sub UpdateCart() End Sub 

Default.aspx.cs

How can I access UpdateCart() on the Default.aspx.cs page?

+8
source share
3 answers

On the Contents page, you can use this to achieve this requirement:

B. B.

 TryCast(Me.Master, MyMasterPage).UpdateCart() 

FROM#

 (this.Master as MyMasterPage).UpdateCart(); 
+18
source share

Do it like this:

 SiteMaster master = new SiteMaster(); //now call the master page method master.test() 

Example

 //master page code behind public partial class SiteMaster : System.Web.UI.MasterPage { protected void Page_Load(object sender, EventArgs e) { } //test method public void test() { } } //content page code behind public partial class About : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { SiteMaster master = new SiteMaster(); master.test(); } } 
+1
source share

Or make the SiteMaster method static and just call it directly:

 SiteMaster.MyStaticMethod() 
0
source share

All Articles