Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ASP.NET - How to make 2 custom user controls communicate with each other?

Posted on 2009-04-02
6
Medium Priority
?
387 Views
Last Modified: 2013-11-08
I'm working on an update of my website - building a customer portal.  One feature will have a "Master" list of sites in a gridview with a "Details" list of sites in a Formview.  

I have created both user controls and placed in a page.  I've left the "SiteID" (DataKey of the Master gridview) parameter of the Details Formview Datasource blank - because I want it to bind to the DataKey of the Master Gridview when the row is selected in the codebehind.

I've been searching all day for an answer to this - everything I find is kind of complex and written in C#.  I'm a VB.Net guy and reverse engineering custom C# classes to VB gives me headaches.

Can anyone point me to a place where I can find the answer? (I'll even buy a book if I can find the right one).  I know an answer to this would be simply putting everything in the same page and scrapping the custom control idea - but I really want to keep the site cleaner.  

There has to be a way to make an event on Control A Send an event and value to Control B to databind Control B...right?
0
Comment
Question by:chrisrbloom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
6 Comments
 
LVL 19

Expert Comment

by:daveamour
ID: 24057630
Hi Chris
I believe I can help you with this but I will guide you rather than writing any code as a) I'm quite busy and b) I'm a C# coder!
If we have a page with 2 controls on and we want control a to send a message to control b then the correct way is to use events.
So first of all do you understand delegates and events in .net?
0
 
LVL 3

Author Comment

by:chrisrbloom
ID: 24058571
Thanks for the comment.  I understand events, methods and properties as they relate to objects, but I do not understand delegates and what exactly they do.
0
 
LVL 19

Accepted Solution

by:
daveamour earned 1000 total points
ID: 24058631
Well an event is a delegate so, with respect, maybe you are not 100% sure about events?
In essense your control a will raise an event and control b will have subscribed to that event and this will have been orchestrated by the page object.
A slighly different model would be for the page to subscribe itself to the event raised by control a and then it will issue a method call on control b passing in data received from the event raised in control a.  Again the core of this is events and delegates.
I have written some articles on delegates and events which I think are well worth a read although they do use C# though.
These are at:
http://www.audacs.co.uk/ViewPage.aspx?PageID=474
http://www.audacs.co.uk/ViewPage.aspx?PageID=476
 
 
 
0
 
LVL 1

Assisted Solution

by:alexandremattar
alexandremattar earned 1000 total points
ID: 24077234
Hello,

I have the solution for you, the way is pretty simple.
Create a property in the WUC in which the attribute you want to become public.
Below an example of how I did, the two user controls are the same html. To find the name of the WUC page only look at the generated name in the html browser.
Source-code-WUC-1-and-WUC-2.doc
0
 
LVL 3

Author Comment

by:chrisrbloom
ID: 24077287
Thanks for the help.  I've read through daveamour's blog posts and now have a much better understanding of events and delegates - and thank you alexandremattar for your doc with code.  I'm working on putting them together to see if I can make this work.
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
Learn how to set-up PayPal payment integration in your Wufoo form. Allow your users to remit payment through PayPal upon completion of your online form. This is helpful for collecting membership payments, customer payments, donations, and more.

664 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