Solved

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

Posted on 2010-08-14
3
363 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
[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
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

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!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

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