Access user control from other user control

C

Chris Zopers

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("FirstUserControl")

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
 
D

David Bunge

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

Nanda Lella[MSFT]

I assume both the UserControls are in the same page. If So, You can use
public properties in both the UserControls and set them when needed.
I have poseted a similar article with example code here
http://ctrlf5.net/?p=53

--

Thank You,
Nanda Lella,
http://www.CtrlF5.net
This Posting is provided "AS IS" with no warranties, and confers no rights.
 

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

Top