Click here to Skip to main content
15,895,084 members
Articles / Web Development / ASP.NET

Introducing ASP.NET Page Modules

Rate me:
Please Sign up or sign in to vote.
3.81/5 (10 votes)
15 Apr 2010CPOL3 min read 57.5K   360   48  
This article introduces the concept of Page Modules, which are similar to HTTP Modules but related to Page Life Cycle, and the need for them.
using System;
using System.Web.UI;
using PauloMorgado.Web.UI;

/// <summary>
/// Summary description for HttpModule
/// </summary>
public class MasterModule : IPageModule
{
    public MasterModule()
    {
    }

    #region IPageModule Members

    public void Init(PageHandlerFactoryWithModules context)
    {
        context.PageCreated += PageCreatedHandler;
    }

    #endregion

    private static void PageCreatedHandler(object sender, PauloMorgado.Web.UI.PageEventArgs e)
    {
        e.Page.PreInit += PagePreInit;
    }

    private static void PagePreInit(object sender, EventArgs e)
    {
        Page page = (sender as Page);

        if (page.MasterPageFile != null)
        {
            page.MasterPageFile = "~/Site.master";
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Paulo Morgado
Portugal Portugal

Comments and Discussions