Accessing user controls at page level using asp.net web forms

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,

Rit
LVL 1
rito1Asked:
Who is Participating?
 
Obadiah ChristopherConnect With a Mentor Commented:
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
{
       get
       {
           return txt1;
        }
}

Open in new window


// In aspx page you can access the control using this property
     myControl.txt1TextBox;

Open in new window

0
 
rito1Author Commented:
Excellent, thank you very much.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.