By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,444 Members | 3,182 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,444 IT Pros & Developers. It's quick & easy.

Accesss User Control Class From Containing Page

P: n/a
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
Aug 8 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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" wrote:
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
Aug 8 '07 #2

P: n/a
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" <Se*****************@discussions.microsoft.comwrot e
in message news:46**********************************@microsof t.com...
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" wrote:
>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

Aug 8 '07 #3

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

--
Regards,

Fred Chateau
fchateauAtComcastDotNet
"Fred Chateau" <fc******@127.0.0.1wrote in message
news:ee**************@TK2MSFTNGP03.phx.gbl...
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" <Se*****************@discussions.microsoft.com>
wrote in message
news:46**********************************@microsof t.com...
>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" wrote:
>>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


Aug 8 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.