• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 878
  • Last Modified:

using findcontrol on a usercontrol

I have 2 user controls say user1.ascx and user2.ascx. I need to do a find the label control on user1.ascx find its value and use it in user2.ascx.Both the controls are on the same page. How can this be achieved in C#?
1 Solution
Gary DavisDir Internet SvcsCommented:
If the control is on the code-infront rather than dynamically created, it should just be accessible by its name.

Gary Davis
J SSenior Systems AdministratorCommented:
You can accomplish this a few ways.

Assuming you have your controls labels text values readable from properties.
lets say user1.ascx has an id of "test1" and user2.ascx has an id of "test2"

in whatever block of code your logic requires

//if the controls are added dynamically
TypeOfControl1 c = Page.FindControl("test1");
TypeOfControl2 c2 = Page.FindControl("test2");
if( c != null && c2 != null)
    //find the user2 control
    c2.LabelProperty = c.LabelProperty;

//if the controls are on the page at design time
test1.LabelProperty = test2.LabelProperty
Forced accept.

EE Admin
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now