title: Accessing sitecore sublayout properties in a usercontrol
body: <hr>
  
  <p>I have a sublayout that has an asp.net wizard.  For each wizard step I want to be able to call a asp.net user control to display the content.  </p>
  
  <p>I created a template that has some fields and I want to be able to access these fields in my user controls. </p>
  
  <p>In my user control I tried getting my sublayout by doing the following:</p>
  
  <pre><code>Sublayout thisSublayout = (Parent as Sublayout);
  </code></pre>
  
  <p>But this returns a null.  </p>
  
  <p>Any ideas what I'm doing wrong?</p>
  
  <p>Thanks in advance.</p>
  
  <p>Below is the code i'm using:</p>
  
  <p><strong>MySublayout.ascx</strong></p>
  
  <p>All i'm doing here is dropping my user control on the page.  The template that I associate with this sublayout has a "My Template Field".</p>
  
  <pre><code>&lt;uctrl:MyNestedUC ID="ucMyUserControl" runat="server" &gt;
  
  &lt;/uctrl:MyNestedUC&gt;
  </code></pre>
  
  <p><strong>MyNestedUC.ascx</strong></p>
  
  <p>This page just has a scText attribute on it:</p>
  
  <pre><code>&lt;sc:Text runat="server" ID="scMyTemplateField" Field="My Template Field" /&gt;
  </code></pre>
  
  <p><strong>MyNestedUC.ascx.cs</strong></p>
  
  <p>In my pageload method this is all i'm doing:</p>
  
  <pre><code>scMyTemplateField.Item = Sitecore.Context.Item;
  </code></pre>
  
  <p>The scMyTemplateField is null so trying to access scMyTemplateField.Item returns a null reference error.</p>
  
  <p>The directives at the top of each page look like this:</p>
  
  <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="My Sublayout.ascx.cs" Inherits="Sublayouts.content.My_Sublayout" %&gt;
  &lt;%@ Control Language="C#" AutoEventWireup="true" CodeBehind="MyNestedUC.ascx.cs" Inherits="Controls.MyNestedUC" %&gt;
  </code></pre>