Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8476551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T18:12:38+00:00 2026-06-10T18:12:38+00:00

I have 2 user controls in an ASPX page. By default the second user

  • 0

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:

TextBox txtLocation = (TextBox)PI_CompLocationTree.FindControl("txtLocation");
txtLocation.Enabled = false;

But i am getting txtLocation as null. How do I get the control in the ASPX page from the ASCX control?

My Updated Code..In Aspx page..

<%@ Register Src="~/UserControl/PI_CompLocationTree.ascx" TagName="PI_CompLocationTree"
TagPrefix="uc1" %>

 <div id="Div2">
   <div class="location">
      <div class="usLocation">
           <uc1:PI_CompLocationTree ID="PI_CompLocationTree1" runat="server"/>
       </div>
   </div>
 </div>

In Page Load…

 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;
 }

In ASCX Page…

<asp:TextBox ID="txtLocation" CssClass="fadded_text fadded_text_ctrl" Style="width: 260px;
float: left;" runat="server" Text=""></asp:TextBox>

In ASCX Code Behind…

public partial class PI_CompLocationTree : System.Web.UI.UserControl
{
    public bool EnabledTextBox
    {
        get { return txtLoc.Enabled; }
        set { txtLoc.Enabled = value; }
    } 
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T18:12:40+00:00Added an answer on June 10, 2026 at 6:12 pm

    Use FindControl Methods as Follow..

    1.  UserControlClass objOfUserControl = (UserControlClass)Page.FindControl("UserControlID");
        TextBox txtLocation= objOfUserControl.FindControl("txtLocation");
        txtLocation.Enabled = false; 
    

    2.You Can Also use Public Property as Follow

    In User Control Codebehind

    public bool TextBoxUSC
    {
      set{txtLocation.Enabled = value;}
    }
    

    In Aspx Code Behind

    UserControlClass.TextBoxUSC=false;
    

    If You are using Master Page

        ContentPlaceHolder cph = (ContentPlaceHolder)this.Page.Master.FindControl("MainContent");//"MainContent" is ContentPlaceHolder's ID
    
        UserControlClass userCntrl = (UserControlClass)cph.FindControl("UserControlID");
        userCntrl.TextBoxUSC = false;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have default.aspx page and one user control. usercontrol is having following code for
I have a default.aspx file and 2 user controls. Code for user control 1
I have a user control loaded on the default.aspx page using the Control UControl
I have a aspx page (default.aspx), inside which I am loading a user control
my structure is like this: master page aspx(web form) ascx(user control) I have a
I have Default.aspx with several controls along with Uploadify Image upload control and i
I have a ASP.NET page with 2 user controls registered. The first one has
1-I have three user controls. 2-I added them to AJAX TabContainer on my default.aspx
I have a user control that programmatically includes a second user control several times,
I have two user controls inside an ASPX page. All I want to do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.