The second aspect is IMO is better. The first option associates the page with a specific main page, and this is not nice.
All files are placed in one folder.
IPageInterface.cs:
namespace CallFromMasterPage { public interface IPageInterface { void DoSomeAction(); } }
Default.aspx.cs:
namespace CallFromMasterPage { public partial class Default : System.Web.UI.Page, IPageInterface { public void DoSomeAction() { throw new NotImplementedException(); } } }
Site.Master.cs:
namespace CallFromMasterPage { public partial class SiteMaster : System.Web.UI.MasterPage { protected void Button1_Click(object sender, EventArgs e) { IPageInterface pageInterface = Page as IPageInterface; if (pageInterface != null) { pageInterface.DoSomeAction(); } } } }
There are other approaches. For instance. You can publish an event through an event broker .
source share