• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 871
  • 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#?
0
joshisanoob
Asked:
joshisanoob
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
0
 
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
0
 
Computer101Commented:
Forced accept.

Computer101
EE Admin
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

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