473,406 Members | 2,371 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Accesss User Control Class From Containing Page

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
3 1322
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Alphonse Giambrone | last post by:
I have a web form with 2 user controls on it (UC1 and UC2). Each control has a bound datagrid with textboxes in the footer to add a new row. There are also requiredfieldvalidators in each footer....
1
by: dickson.matt | last post by:
OK, I have created a user control that contains a dropdown for office locations. Here is the code.... Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles...
11
by: trinitypete | last post by:
Hi all, I have a user control that uses control literal to build a heading with a link, and a div containing links below. As the link heading is hit, I want to change the style of the div,...
0
by: Jo Inferis | last post by:
Disclaimer : I'm fairly new to .NET (about 4 weeks and counting now...) I have a page which contains multiple user controls, some of which it has access to the methods of (by making the controls...
6
by: guoqi zheng | last post by:
In a regular html form, when user press "enter" key, the form will be submitted. However, in ASP.NET web form, a form will only be submitted (post back) when a special button is clicked. Many...
4
by: louise raisbeck | last post by:
Resending this as own topic as didnt get answer from original. Would be grateful for a response from anyone that knows. Thanks. Hi there, I found your post really helpful..but i wondered if, once...
7
by: Mr Newbie | last post by:
Hi There, Here I am messing about with User Controls and I seem to have a conundrum on my hands which I'm sure you chaps will unravel for me in the blink of an eye.
1
by: Efi Merdler | last post by:
Hi, I created a user control, but instead of handling exception in the user control level I prefer to handle them in the containing form. In the load event of the containing form I'm using:...
5
by: Fred Chateau | last post by:
I am trying to reference a server control in a user control, from the containing page. Is there a way to do that? I have tried "UserControl1.FindControl("ControlName")" but I get a null reference....
3
by: Fred Chateau | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.