Solved

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

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
API v SOA 8 39
I need help changing the default value for an @HTML.LabelFor control 4 36
c#, case, if 4 18
Web page design problem 3 14
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 …
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
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 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.

756 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