How to access Master page controls from the Content page

How to access Master page controls from the Content page

 

At first, use the Page.Master property to get a reference to the actual master page instance, the use the Master.FindControls method to find and reference the controls declared in the Master page.

 

For example,

MasterPage master = Page.Master;

UserControl headerControl = (UserControl)(master.FindControl("PageHeader1"));

HtmlImage imgHead = (HtmlImage)(headerControl.FindControl("img0Category"));

if(imgHead != null)

{

          imgHead.Src = "/images/categoryb.gif";

}

 

 

posted @ 2006-07-19 23:39  Rickie  阅读(1007)  评论(0编辑  收藏  举报