Passing Data Between User Controls

Posted on 2008-11-12
Last Modified: 2013-12-17
I have two User Controls.   When a button is clicked on one of them.....I need to pass data to a control in the other User Control.

Is it best to raise an event......use a delegate?.......or add a reference to User Control 1 and then try to access the control in the User Control 2 code? or vice versa?  :)

This was originally written in VB6.   I had to have binary compatibility between the two ....which was a pain in the butt because I had to rebuild both everytime I made a change.

Im new in the C# realm so please leave details. :)  


Question by:JohnnyKnoxville
    1 Comment
    LVL 7

    Accepted Solution

    If you use events, then the controlling form would take care of the communications for you.  I would certainly go this route since I would not care for my controls to know about each other.
    So in your form, watch the first control's event, and have your form update the second button for you.
    private void button1_Click( object sender, EventArgs e )
        button2.Text = button1.Text;

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Normally a window is moved by clicking on the caption bar and dragging. You may want your user to be able to move borderless forms or move a form by clicking anywhere in the form without the limitation to the caption bar. There are many ways to do i…
    A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    779 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

    9 Experts available now in Live!

    Get 1:1 Help Now