Solved

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

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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!
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

685 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