title: setting value in MasterPage from UserControl
body: <p>I have the following situation:</p>
  
  <p>A MasterPage MyMaster.Master</p>
  
  <p>A Content Page Content.aspx</p>
  
  <p>A UserControl MyUserControl.ascx</p>
  
  <p>MyUserControl.ascx is being used in Content.aspx and is being added programatically. The content page is using MyMaster.Master</p>
  
  <p>MyMaster.Master has a variable which I can access from Content.aspx as I have the @MasterType directive set. What I am wanting to do is the following:</p>
  
  <p>1) Set a value in MyUserControl.ascx</p>
  
  <p>2) Access value from Content.aspx</p>
  
  <p>3) Set value in MyMaster.Master</p>
  
  <p>Step 2 is implemented in the PageLoad of content.aspx as follows:</p>
  
  <pre><code>Control ucControl= LoadControl("/UserControls/MyUserControl.ascx");
  UserControls_MyUserControl myUC = ucControl as UserControls_MyUserControl;
  //Do some caching stuff here
  if (myUC != null)
      myUC.PreRender += new EventHandler(myUC_PreRender);
  </code></pre>
  
  <p>The PreRender handler just sets a value in MyMaster.Master to true. In MyMaster.Master I check that value in PageLoad and try display something if it is true. This does not work.</p>
  
  <p>I suspect it has something to do with the Page Lifecycle, but I cannot seem to find which part is wrong.</p>
  
  <p>Any help much appreciated.</p>
  
  <p>Thanks</p>