Skip to content
February 5, 2011 / pauldundon

Notifying a Master Page of Events on the Page

The Problem: You have an ASP.NET web page using a master page. You want to invoke some code in the master page in response to an event on the page (eg a change to a text box).

Rejected solutions: One approach is to provide a public method on the master page and invoke it from the page. This approach works but tightens the coupling between the two classes, coupling which may be replicated across multiple pages, and which makes abstraction of the relevant code on the page more difficult. Using an interface to mediate the coupling lessens this problem but not so well as the following solution.

Possible solution: Invoke RaiseBubbleEvent in the page and override OnBubbleEvent in the master page. If the originating event is a button click which is not handled elsewhere, the first step is not needed as the framework will invoke OnBubbleEvent in the master page.



Leave a Comment
  1. Ken / May 9 2014 9:01 pm

    Have you even tested this? It doesn’t work

    • pauldundon / May 14 2014 9:26 pm

      I have tested it, and it does work – I can provide sample code if that helps.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: