Set Masterpage from Global.asax in ASP.NET

Posted by StefanE on Stack Overflow See other posts from Stack Overflow or by StefanE
Published on 2010-05-21T12:09:14Z Indexed on 2010/05/21 12:40 UTC
Read the original article Hit count: 239

Filed under:

Hi,

I want to set the Masterpage property in Global.asax.

This is what I have done but I get a NullReferenceException on the first line. Any ideas how to do this?

protected void Application_PreSendRequestContent(Object sender, EventArgs e)
{
    System.Web.UI.Page page = System.Web.HttpContext.Current.Handler as System.Web.UI.Page;               

    if (Session["lang"] == "eng")
    {
        page.MasterPageFile = "SideMasterPageEng.master";
    }
}

© Stack Overflow or respective owner

Related posts about ASP.NET