Removing Master Page at Run Time

by Bill Beckelman 5/14/2008 10:45:21 AM

I have needed to figure out how to do this for a while to avoid having to create multiple pages with nearly the same code when I want send a report for printing or conversion to PDF. Turns out this is really simple. The easiest way I found was not to remove the master page, but to replace it with a blank master page in the Page_PreInit event.

 

    protected void Page_PreInit(object sender, EventArgs e)
    {
        if (Request.QueryString["Report"] == "true")
        {
            Page.MasterPageFile = "~/BlankMasterPage.master";
        }
    }

Currently rated 4.0 by 1 people

  • Currently 4/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ASP.NET

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag

[b][/b] - [i][/i] - [u][/u]- [quote][/quote]



Live preview

7/3/2008 4:47:21 PM



Powered by BlogEngine.NET 1.3.0.29
Theme by Mads Kristensen

About the author

Name of author Bill Beckelman
I live and work in South Jordan, Utah

E-mail me Send mail

Calendar

<<  July 2008  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

Pages

    Recent comments

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2008

    Sign in