Solved

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

Posted on 2009-04-02
6
379 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
  • 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 250 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 250 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

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

Foreword (May 2015) This web page has appeared at Google.  It's definitely worth considering! https://www.google.com/about/careers/students/guide-to-technical-development.html How to Know You are Making a Difference at EE In August, 2013, one …
It’s a strangely common occurrence that when you send someone their login details for a system, they can’t get in. This article will help you understand why it happens, and what you can do about it.
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

705 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

14 Experts available now in Live!

Get 1:1 Help Now