Reputation: 5592
Whats the best way to transfer data between the master page and the content page? I am accessing a rather large cache in the master page to display some information but the content page also needs to access the cache. So instead of loading the cache twice i thought it would be better to get the cache from the master page.
I created an interface witch i then use in my master page.
IMaster: myClass GetDataCache { get; }
MasterPage: public partial class main : System.Web.UI.MasterPage, IMaster
Then i cast the master page inside my content page and retrieve the cache.
IMaster masterPage = (IMaster)Master;
myClass = masterPage.GetDataCache;
My question is, is this the best way to handle data between a master page and a content page?
Upvotes: 0
Views: 728
Reputation: 22709
I would rather leave the master page for the UI only.
The better way would be to have a static singleton class accessible from all content pages for this purpose.
Upvotes: 0
Reputation: 40756
Use the MasterType directive inside the ASPX page to get a strongly typed reference to the master page from within your content page (and from the code-behind of your content page).
Upvotes: 1