BeanSoftware Logo
 

 
ASP.NET Database Search Control
 
 

 
 Home
    Shop
    Advertise
    Write For Us
    Affiliate
    Newsletter
    Contact

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

FAQ toolbar: Submit FAQ  |  Tell A Friend  |  Add to favorites  |  Feedback



Copyright © 2002-2008 Bean Software. All rights reserved.