Solved

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

Posted on 2009-04-02
6
380 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
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…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

920 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