How To Access Control On Master Page From Content Page
Very common case is that you need to change something on Master page by using a server side ASP.NET code from content page. For example, that could be some Label control or Title, but also anything else like rich data controls GridView, Repeater etc.
To access control located in Master page with code from content page, use FindControl method. Let say you need to access to Repeater control located on Master page and set its data source. Code could look like this:
[ C# ]
// Get reference to control located on master page
Repeater rp = (Repeater)Page.Master.FindControl("Repeater1");
// Set data source
rp.DataSource = dtProducts; // dtProducts is DataTable that contains needed recordset
rp.DataBind();
[ VB.NET ]
' Get reference to control located on master page
Dim rp As Repeater = Page.Master.FindControl("Repeater1")
' Set data source
rp.DataSource = dtProducts ' dtProducts is DataTable that contains needed recordset
rp.DataBind()
Related articles:
1. Master Pages in ASP.Net 2.0 - An Advanced Look