Sending Event from a Page to its Master Page in ASP.NET?

Edit, from what your asking you don't really need an event, you just want to call a method on the master. Off the top of my head, in the master.

Edit, from what your asking you don't really need an event, you just want to call a method on the master. Off the top of my head, in the master: public void ChangeCss(string className) { someObject. CssClass = className; } then in your page: (this.

Master as MyMasterType). ChangeCss("myclass").

Create a base page class. Create the respective delegate & event for the same. Then in the master page, do this - (Page as BasePage).

Event += attach event handler here in the master page. The page class must be like this - public class MyPage : BasePage { } The BasePage class must be like this - public class BasePage : System.Web.UI. Page { } //This will go in the App_Code folder.

If the event happens on all content pages use Kirtan's BasePage solution. If a base page isn't appropriate, then within each page where the event happens add this when the page loads. ThisPage.

Event += (Page. Master as YourMasterPageClass). YourCustomEventHandler.

That worked. Thanks! – Adam Kane Apr 15 '09 at 10:07.

An event doesn't seem like the best way to indicate this, given you need your masterpage to understand your pages, you could well have a standard property on the pages that indicates their 'key' in the navigation. In your masterpage code: protected override void OnInit(EventArgs e) { base. OnInit(e); var navigatable = this.

Page as INavigatable; if (navigatable! = null) this.Navigation. ActiveKey = navigatable .

NavigationKey; } Navigatable interface: public interface INavigatable { string NavigationKey { get; } } Page instance: public class AboutPage : Page, INavigatable { public string NavigationKey { get { return "About"; } } }.

You can raise the event using a technique called as EventBubbling.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions