Solved

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

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Thoughout my experience working on eCommerce web applications I have seen applications succumbing to increased user demand and throughput. With increased loads the response times started to spike, which leads to user frustration and lost sales. I ha…
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…
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…

751 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