using findcontrol on a usercontrol

Posted on 2007-08-03
Last Modified: 2013-12-17
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#?
Question by:joshisanoob
    LVL 18

    Expert Comment

    by:Gary Davis
    If the control is on the code-infront rather than dynamically created, it should just be accessible by its name.

    Gary Davis
    LVL 6

    Accepted Solution

    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
    LVL 1

    Expert Comment

    Forced accept.

    EE Admin

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Suggested Solutions

    After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
    For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
    The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
    The viewer will learn how to synchronize PHP projects with a remote server in NetBeans IDE 8.0 for Windows.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now