Accessing user controls at page level using web forms

Posted on 2012-09-12
Last Modified: 2012-09-12
Hi All,

Is there a better way to access user control (ascx) elements, as in the controls within an ascx control from the aspx page level instead of using myUserControl.findControl().

Is there a way that user controls could be inherited into an aspx page or apply a namespace to my page to make all elements of the user control automatically accessible via the page?

Your help and syntax would be much appreciated.

Many thanks,

Question by:rito1
    LVL 20

    Accepted Solution

    Automatically visible on the page is not possible.

    You could do something like this in the usercontrol

    <asp:TextBox ID="txt1" runat="server" Width="100px"></asp:TextBox>

    Open in new window

    public TextBox txt1TextBox
               return txt1;

    Open in new window

    // In aspx page you can access the control using this property

    Open in new window

    LVL 1

    Author Closing Comment

    Excellent, thank you very much.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    This video is in connection to the article "The case of a missing mobile phone (". It will help one to understand clearly the steps to track a lost android phone.
    This video discusses moving either the default database or any database to a new volume.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now