title: Update MasterPage control from Content page
body: <p>I have an <code>UpdatePanel</code> with a <code>Label</code> which I would like to update in my <code>MasterPage</code>. The event is taking place from my Content page and here are the codes.</p>
  
  <p>Content ASP.net code:</p>
  
  <pre><code>&lt;%@ MasterType TypeName="OnBoarding.Pages.Site" %&gt;
  &lt;asp:DropDownList ID="ddlTaskName" CssClass="chosen-select" DataSourceID="dsPopulateTaskName" AutoPostBack="true" DataValueField="Task Name" runat="server" Width="100%" Font-Size="11px" AppendDataBoundItems="true" OnSelectedIndexChanged="ddlTaskName_onSelectIndexChanged"&gt;
      &lt;asp:ListItem Text="All" Value="%"&gt;&lt;/asp:ListItem&gt;
  &lt;/asp:DropDownList&gt;
  &lt;asp:SqlDataSource ID="dsPopulateTaskName" runat="server" ConnectionString="&lt;%$ ConnectionStrings:gvConnString %&gt;" SelectCommand="QUERY"&gt;&lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>C# code-behind:</p>
  
  <pre><code>protected void ddlTaskName_onSelectIndexChanged(object sender, EventArgs e)
  {
      FilterMessages();
  }
  
  public void FilterMessages()
  {
          DataTable msgTable = HttpContext.Current.Session["MessageTable"] as DataTable;
          string query = "";
          Stack msgStack = new Stack();
  
          if (ddlClient.SelectedIndex &gt; 0)
          {
              query += "Client = '" + ddlClient.SelectedItem.Text + "' OR Client is NULL";
          }
          if (ddlSite.SelectedIndex &gt; 0 &amp;&amp; query == "")
          {
              query += "Site = '" + ddlSite.SelectedItem.Text + "' OR Site is NULL";
          }
          else if (ddlSite.SelectedIndex &gt; 0)
          {
              query += " AND Site = '" + ddlSite.SelectedItem.Text + "' OR Site is NULL";
          }
  
          if (ddlProvider.SelectedIndex &gt; 0 &amp;&amp; query == "")
          {
              query += "Provider = '" + ddlProvider.SelectedItem.Text + "' OR Provider is NULL";
          }
          else if (ddlProvider.SelectedIndex &gt; 0)
          {
              query += " AND Provider = '" + ddlProvider.SelectedItem.Text + "' OR Provider is NULL";
          }
          UpdatePanel upMsg = (UpdatePanel)Master.FindControl("upMessage");
          if (query != "")
          {
              DataRow[] result = msgTable.Select(query);
              System.Web.UI.WebControls.Label lblMsg = (System.Web.UI.WebControls.Label)Master.FindControl("lblMessage");
              if (lblMsg != null)
              {
                  lblMsg.Text = "";
              }
              //lblMessage.Text = "";
              foreach (DataRow row in result)
              {
                  if (row["Active"].ToString() == "True")
                  {
                      string[] myStrings = new string[] { row["Created"].ToString().Split(' ')[0], string.IsNullOrEmpty(row["Client"].ToString()) ? null : row["Client"].ToString(), string.IsNullOrEmpty(row["Site"].ToString()) ? null : row["Site"].ToString(), row["Message"].ToString() };
                      string strResult = string.Join(" ", myStrings.Where(str =&gt; !string.IsNullOrEmpty(str)));
                      msgStack.Push(strResult);
                  }
              }
              foreach (string message in msgStack)
              {
                  lblMsg.Text += message + "&lt;/br&gt;";
                  //lblMessage.Text += message + "&lt;/br&gt;";
              }
          }
          else
          {
              PopulateMessageGV();
          }
      if (upMsg != null)
      {
          upMsg.Update();
      }
      //upMessage.Update();
  }
  protected void PopulateMessageGV()
  {
      UpdatePanel upMsg = (UpdatePanel)Master.FindControl("upMessage");
      System.Web.UI.WebControls.Label lblMsg = (System.Web.UI.WebControls.Label)Master.FindControl("lblMessage");
      if (lblMsg != null)
      {
          lblMsg.Text = "";
      }
      //lblMessage.Text = "";
      DataTable dt = new DataTable();
      dt.Columns.Add("ID", typeof(int));
      dt.Columns.Add("Created", typeof(string));
      dt.Columns.Add("Message", typeof(string));
      dt.Columns.Add("Client", typeof(string));
      dt.Columns.Add("Site", typeof(string));
      dt.Columns.Add("Provider", typeof(string));
      dt.Columns.Add("Active", typeof(bool));
      dt.Columns.Add("CreatedBy", typeof(string));
  
  
      using (var context = new ClientContext(hostWeb))
      {
          Stack msgStack = new Stack();
  
          var hostSite = context.Web;
          context.Load(hostSite, s =&gt; s.Title);
          context.ExecuteQuery();
  
          ListCollection allLists = hostSite.Lists;
          Microsoft.SharePoint.Client.List messageList = allLists.GetByTitle("AdminMessage");
          context.Load(messageList);
          context.ExecuteQuery();
  
          try
          {
              var query = CamlQuery.CreateAllItemsQuery();
              Microsoft.SharePoint.Client.ListItemCollection allItems = messageList.GetItems(query);
              context.Load(allItems);
              context.ExecuteQuery();
  
              if (allItems.Count &gt; 0)
              {
                  foreach (Microsoft.SharePoint.Client.ListItem item in allItems)
                  {
                      DataRow dr = dt.NewRow();
                      dr["ID"] = item["ID"];
                      dr["Created"] = item["Created"];
                      dr["Message"] = item["Message"];
                      dr["Client"] = item["Client"];
                      dr["Site"] = item["Site"];
                      dr["Provider"] = item["Provider"];
                      dr["Active"] = item["Active"];
                      FieldUserValue test = (FieldUserValue)item["Author"];
                      dr["CreatedBy"] = test.LookupValue.ToString();
                      dt.Rows.Add(dr);
  
                      if (item["Active"].ToString() == "True")
                      {
                          string[] myStrings = new string[] { item["Created"].ToString().Split(' ')[0], string.IsNullOrEmpty(dr["Client"].ToString()) ? null : item["Client"].ToString(), string.IsNullOrEmpty(dr["Site"].ToString()) ? null : item["Site"].ToString(), item["Message"].ToString() };
                          string result = string.Join(" ", myStrings.Where(str =&gt; !string.IsNullOrEmpty(str)));
                          msgStack.Push(result);
                      }
                  }
              }
              HttpContext.Current.Session["MessageTable"] = dt;
              foreach (string message in msgStack)
              {
                  lblMsg.Text += message + "&lt;/br&gt;";
                  //lblMessage.Text += message + "&lt;/br&gt;";
              }
  
              if (upMsg != null)
              {
                  upMsg.Update();
              }
              //upMessage.Update();
          }
          catch (Exception ex)
          {
              string error = ex.Message;
          }
      }
  }
  </code></pre>
  
  <p>MasterPage ASP.net code:</p>
  
  <pre><code>&lt;asp:UpdatePanel runat="server" ID="upMessage" ClientIDMode="Static" UpdateMode="Conditional"&gt;
      &lt;ContentTemplate&gt;
          &lt;asp:Label ID="lblMessage" Font-Size="x-small" runat="server" Text="" ClientIDMode="Static"&gt;&lt;/asp:Label&gt;
      &lt;/ContentTemplate&gt;
  &lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p>When I change the DropDown option the UpdatePanel in the masterpage doesn't update although putting a breakpoint there, shows that it is being hit.</p>
  
  <p>How do I resolve the issue?</p>