Click here to Skip to main content
14,691,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to call a method of content page through master page
Posted

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


ContentPlaceholderPageNameis the ID of the ContentPlaceHolder in your master page. PageBase is the base class containing the YourMethod method.
   
v4
Important Note: You can do it as

Page pg = ContentPlaceholderPageName.Page as Page;
if(pg != null)
{
  pg.Whatever();
}


but i would seriously not recommend that. whenever we see a scenario where master page is referring the content page, we should rethink our design. Always make content page refer to master page. have properties in master page to push data in it. the reason is that the master page should not depend on content page because there will be many content pages using the master page. the reverse dependency is OK and in fact recommended for any master-content page communication.
   
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900