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
Solved

ASP.Net   Help with Event Bubbling - 3 levels of user controls

Posted on 2010-08-14
3
360 Views
Last Modified: 2012-05-10
Hi..
I have a Page, that uses 2 user controls.  
A user clicks 1 buttons on the page and the first user controls is loaded (LoadControl).  If they click a button on the 'new' user control , a  Second user control is loaded.  When the press the 'Update' button on the second user control I need the events to bubble up to the Page - so I can call a method that will reload/refresh the data.  How can I implement this? An example would be great in C#.
thanks
0
Comment
Question by:JElster
  • 2
3 Comments
 
LVL 41

Expert Comment

by:guru_sami
ID: 33436895
Something like this:

UC2 code-Behind:

public delegate void MyUC2Event(object sender, EventArgs e);
public event MyUC2Event MyUC2Event_Handler;

    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (MyUC2Event_Handler!= null)
        {
             MyUC2Event_Handler(sender,e);
        }
    }

ParentPage Code-behind that contains UC1 and UC2.
//This is event handler for MyUC2Event_Handler event
protected void UC2_MyUC2Event_Handler(object sender, EventArgs e)
    {
        // Refresh your page
    }
Check this as well: http://chiragrdarji.blogspot.com/2007/08/raise-event-from-user-control-to-main.html
0
 
LVL 1

Author Comment

by:JElster
ID: 33437753
Hi..

The UC2 is contained in UC1...

Page loads UC1 , UC1 load UC2 into UC1.   When UC2 is clicked I need the event to bubble up into UC1 and then the page.

thanks

0
 
LVL 41

Accepted Solution

by:
guru_sami earned 350 total points
ID: 33438424
If UC2 is in UC1 then move this block into UC1 code behind:
//This is event handler for MyUC2Event_Handler event
protected void UC2_MyUC2Event_Handler(object sender, EventArgs e)
    {
        // Refresh UC1
       //Raise event and handle it in Main Page that has UC1
    }
2: Expose an event similar to one in UC2, raise it from UC1 as shown in comment code above, handle it in Page and Update page data.

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

790 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