title: How to disable user control from code-behind?
body: <p>I have 2 user controls in an ASPX page. By default the second user control should be disabled. In that user control i am having only one text box. So i find the control in the page load event like this:</p>
  
  <pre><code>TextBox txtLocation = (TextBox)PI_CompLocationTree.FindControl("txtLocation");
  txtLocation.Enabled = false;
  </code></pre>
  
  <p>But i am getting txtLocation as null. How do I get the control in the ASPX page from the ASCX control?</p>
  
  <p>My Updated Code..In Aspx page..</p>
  
  <pre><code>&lt;%@ Register Src="~/UserControl/PI_CompLocationTree.ascx" TagName="PI_CompLocationTree"
  TagPrefix="uc1" %&gt;
  
   &lt;div id="Div2"&gt;
     &lt;div class="location"&gt;
        &lt;div class="usLocation"&gt;
             &lt;uc1:PI_CompLocationTree ID="PI_CompLocationTree1" runat="server"/&gt;
         &lt;/div&gt;
     &lt;/div&gt;
   &lt;/div&gt;
  </code></pre>
  
  <p>In Page Load...</p>
  
  <pre><code> PI_CompLocationTree PI_CompLocationTree = new PI_CompLocationTree();
  
   protected void Page_Init(object sender, EventArgs e)
   {
      var userControl = (PI_CompLocationTree)this.FindControl("PI_CompLocationTree1");
      userControl.EnabledTextBox = false;
   }
  </code></pre>
  
  <p>In ASCX Page...</p>
  
  <pre><code>&lt;asp:TextBox ID="txtLocation" CssClass="fadded_text fadded_text_ctrl" Style="width: 260px;
  float: left;" runat="server" Text=""&gt;&lt;/asp:TextBox&gt;
  </code></pre>
  
  <p>In ASCX Code Behind...</p>
  
  <pre><code>public partial class PI_CompLocationTree : System.Web.UI.UserControl
  {
      public bool EnabledTextBox
      {
          get { return txtLoc.Enabled; }
          set { txtLoc.Enabled = value; }
      } 
  }
  </code></pre>