You need to tell the content page what the specific type of the master page is before you can use any public properties\methods on that master page. This can be done using the MasterType derective
Working with ASP.NET Master Pages Programmatically[
^]
Master page has this dropdown
<asp:DropDownList ID="ddlSites" runat="server" OnSelectedIndexChanged="ddlSites_SelectedIndexChanged" AutoPostBack="true">
<asp:ListItem Text="One" Value="1" />
<asp:ListItem Text="Two" Value="2" />
<asp:ListItem Text="Three" Value="3" />
</asp:DropDownList>
master page code-behind - note I'm using a custom delegate to pass the selected value of the dropdown, you can extend that to pass the text too if needed
public partial class SiteMaster : MasterPage
{
public delegate void SiteSelectedEvent(string site);
public event SiteSelectedEvent contentCallEvent;
protected void ddlSites_SelectedIndexChanged(object sender, EventArgs e)
{
if (contentCallEvent != null)
contentCallEvent(ddlSites.SelectedValue);
}
}
User control
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyControl.ascx.cs" Inherits="ProjectNamespace.MyControl" %>
<asp:Literal ID="LiteralResult" runat="server" />
User control code behind - the control exposes a method that allows calling code to pass it data
public partial class MyControl : System.Web.UI.UserControl
{
public void ShowResult (string result)
{
LiteralResult.Text = result;
}
}
Finally the code-behind of the content page. "MyControl1" is the ID of the user control on the page.
protected void Page_Load(object sender, EventArgs e)
{
Master.contentCallEvent += Master_contentCallEvent;
}
private void Master_contentCallEvent(string site)
{
MyControl1.ShowResult(site);
}
Also note the content page has the MasterType directive
<%@ MasterType VirtualPath="~/Site.Master" %>
That will allow the change event of the dropdown on the master page to pass the selected data to any event subscribers, and the content page uses that event to pass the data to the user control via a method. Note we try to never directly access controls that belong to other components, instead things are done via methods etc that de-couple the functionality from the implementation.