469,579 Members | 1,064 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,579 developers. It's quick & easy.

Access user control from other user control

Hello,

I have two UserControls on a aspx page. I need to read a property of the
first UserControl from within the second UserControl. The UserControls
only know about themselves, so I can't declare a variable of the other
usercontrol's type. So I can't do something like this in the second
UserControl:

FirstUserControl first =
(FirstUserControl)this.Parent.FindControl("FirstUs erControl")

Additionally I don't like to use the FindControl method, because it
returns an Object.

What's the best way to get to a usercontrol's properties from within an
other user control?

Greetings,
Chris


*** Sent via Developersdex http://www.developersdex.com ***
Feb 20 '08 #1
2 1471
In the first user control, you can declare a property of the type matching
the second user control and set this property from the page containing both
controls.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
"Chris Zopers" <te***********@12move.nlwrote in message
news:OX**************@TK2MSFTNGP03.phx.gbl...
Hello,

I have two UserControls on a aspx page. I need to read a property of the
first UserControl from within the second UserControl. The UserControls
only know about themselves, so I can't declare a variable of the other
usercontrol's type. So I can't do something like this in the second
UserControl:

FirstUserControl first =
(FirstUserControl)this.Parent.FindControl("FirstUs erControl")

Additionally I don't like to use the FindControl method, because it
returns an Object.

What's the best way to get to a usercontrol's properties from within an
other user control?

Greetings,
Chris


*** Sent via Developersdex http://www.developersdex.com ***

Feb 21 '08 #2
How would you go about doing this? Could you post an example?

I have one user control declared as "public partial class
controls_SecondaryDisabilities : System.Web.UI.UserControl" on a page
with a second user control declared as "
public partial class controls_StateList : System.Web.UI.UserControl".

I need to get a value from the second user control (the StateList) into
a variable in the first (the SecondaryDisabilities). The value is a
public string, so it is accessible. However, when I declare "protected
controls_StateList ddlPartState;", the controls_StateList is not being
found.

Thank you in advance.

*** Sent via Developersdex http://www.developersdex.com ***
Aug 5 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Peter Frost | last post: by
49 posts views Thread by Yannick Turgeon | last post: by
5 posts views Thread by djscratchnsniffing | last post: by
1 post views Thread by =?Utf-8?B?SlA=?= | last post: by
16 posts views Thread by Ben Sehara | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.