title: Get and cast Masterpage UserControl from Content Page to access specific UC Property
body: <p>I have a MasterPage (MyBoxx.Master) referencing 2 usercontrols :</p>
  
  <pre><code>&lt;%@ Master Language="C#" AutoEventWireup="true" CodeFile="MyBoxx.master.cs" Inherits="MyBoxxMaster" %&gt;
  &lt;%@ Register TagPrefix="uc1" TagName="Header" Src="Header.ascx" %&gt;
  &lt;%@ Register TagPrefix="uc1" TagName="Footer" Src="Footer.ascx" %&gt;
  </code></pre>
  
  <p>My user control "Header" contains among other things a searchbox. I want to hide this searchbox when visiting some pages. Therefore I added a boolean property to my user control and use this property when rendering the usercontrol to determinate whether to display the search box or not :</p>
  
  <pre><code>public partial class uxHeader : System.Web.UI.UserControl
  {
  
      bool _showSearch = true;
      public bool ShowSearch
      {
          get { return _showSearch; }
          set { _showSearch = value; }
      }
      [...]
      protected void Page_Load(object sender, EventArgs e)
      {
          [...]
          searchBox.Visible = _showSearch;
  
      }
  }
  </code></pre>
  
  <p>I then try to access this "ShowSearch" Property from the content page :  </p>
  
  <pre><code>((uxHeader)Page.Master.FindControl("Header1")).ShowSearch = false;
  </code></pre>
  
  <p>Problem is I get the following error when trying to compile :</p>
  
  <pre><code>Error   15  The type or namespace name 'uxHeader' could not be found (are you missing a using directive or an assembly reference?)
  </code></pre>
  
  <p>The thing is I'm sure I got it to work and compile at some point as it works on the previously released production version. But now I'm doing a change to something else in the same site, and can't compile anymore. </p>
  
  <p>From various post on SO, I tried adding the following lines to my content page aspx :</p>
  
  <pre><code>&lt;%@ MasterType VirtualPath="~/MyBoxx.master"%&gt;
  &lt;%@ Reference VirtualPath="~/MyBoxx.master" %&gt;
  </code></pre>
  
  <p>Without any success ! I saw also some answers about the page Lifecycle, but this can't be the problem here as I'm getting an error on compilation, not a bug upon execution.</p>
  
  <p>If anyone has any advice on how I can fix this for good, I would grandly appreciate.</p>
  
  <p>Thanks !</p>