Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

Accesss User Control Class From Containing Page

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Fred Chateau - 08 Aug 2007 05:21 GMT
I am trying to access a user control class, for a user control that is
loaded dynamically, from the containing page. I have been able to access Web
controls in the user control, but so far I have been unable to expose the
user control class itself. I'm guessing that I need to set up an interface,
but I am not sure how to accomplish this.

Here is the code that loads the user control:

protected void Page_Init(object sender, EventArgs e)
{
UserControl bottomPanel = (UserControl) LoadControl("~/Reviews.ascx");
bottomPanel.ID = "Reviews_ascx";
PlaceholderUserControl.Controls.Add(bottomPanel);
}

----
Here is how I access Web controls in the user control:

PlaceholderUserControl.Controls[0].FindControl("radReview");

----

I need to set a property of the user control for data access, but this is a
far as I've been able to go.

Signature

Regards,

Fred Chateau
fchateauAtComcastDotNet

Sergey Poberezovskiy - 08 Aug 2007 07:00 GMT
Fred,

Usually user controls (as well as web controls) do not expose internal
control structure, but rather public properties/methods that allow
manipulating them - the internal structure of the controls should not be
known or relied upon by the consumers.

> I am trying to access a user control class, for a user control that is
> loaded dynamically, from the containing page. I have been able to access Web
[quoted text clipped - 20 lines]
> I need to set a property of the user control for data access, but this is a
> far as I've been able to go.
Fred Chateau - 08 Aug 2007 08:10 GMT
That is exactly what I am trying to do. I want to expose the user control's
internal properties as public properties of the user control class, but I do
not know how to get a reference to the user control class from the
containing page. I can get a reference to the Web controls in the user
control, but after exposing public properties of the Web controls in the
user control class, how do I get a reference to the user control class
itself?

Signature

Regards,

Fred Chateau
fchateauAtComcastDotNet

> Fred,
>
[quoted text clipped - 30 lines]
>> a
>> far as I've been able to go.
Fred Chateau - 08 Aug 2007 09:35 GMT
I found it. I needed to add the  <%@ reference control="~/ControlName.ascx"
%> directlve to the page.

Signature

Regards,

Fred Chateau
fchateauAtComcastDotNet

> That is exactly what I am trying to do. I want to expose the user
> control's internal properties as public properties of the user control
[quoted text clipped - 39 lines]
>>> is a
>>> far as I've been able to go.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.