Accesss User Control Class From Containing Page

F

Fred Chateau

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

Guest

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.
 
F

Fred Chateau

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?

--
Regards,

Fred Chateau
fchateauAtComcastDotNet


Sergey Poberezovskiy said:
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.


Fred Chateau said:
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.

--
Regards,

Fred Chateau
fchateauAtComcastDotNet
 
F

Fred Chateau

I found it. I needed to add the <%@ reference control="~/ControlName.ascx"
%> directlve to the page.

--
Regards,

Fred Chateau
fchateauAtComcastDotNet


Fred Chateau said:
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?

--
Regards,

Fred Chateau
fchateauAtComcastDotNet


"Sergey Poberezovskiy" <[email protected]>
wrote in message
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.


Fred Chateau said:
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.

--
Regards,

Fred Chateau
fchateauAtComcastDotNet
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top