Solved

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

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

20 Experts available now in Live!

Get 1:1 Help Now