title: Finding a field on user control form
body: <p>I have a field 'x' on the user control form which is included on aspx page and that page using SharePoint master page. I'm trying to locate field x on aspx page in my code but it throws "Object ref not set" error. I've tried following but nothing works ,</p>
  
  <pre><code>((TextBox)Page.Master.FindControl("PlaceHolderMain").FindControl("Experience").FindControl("x")).Text
  
  
  ((TextBox)this.FindControl("x")).Text
  
  
  ((TextBox)Page.Master.FindControl("PlaceHolderMain").FindControl("x")).Text
  </code></pre>
  
  <p>I can locate the field on page source,</p>
  
  <pre><code>&lt;input name="ctl00$PlaceHolderMain$ctl00$x" type="text" value="3" id="ctl00_PlaceHolderMain_ctl00_x" class="textbox" /&gt;
  </code></pre>
  
  <p><strong>Update:-</strong></p>
  
  <p>Previously I was adding user control programmatically on load event of the aspx page,</p>
  
  <pre><code>UserControl uc = (UserControl)Page.LoadControl("Experience.ascx");
  experineceForm.Controls.Add(uc);
  </code></pre>
  
  <p>But by seeing page source I had doubt and thought to add it in design time using following code,</p>
  
  <pre><code>&lt;%@ Register TagPrefix="uc" TagName="Experience" Src="Experience.ascx" %&gt;
  
  &lt;div id="experineceForm" runat="server"&gt;
     &lt;uc:experience id="idExperienceForm" runat="server"/&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>After doing this I'm able to find controls with following code,</p>
  
  <pre><code>((TextBox)Page.Master.FindControl("PlaceHolderMain").FindControl("idExperienceForm").FindControl("txtEmployeeComments")).Text
  </code></pre>