Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

813 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

15 Experts available now in Live!

Get 1:1 Help Now