master pages

  • Thread starter Thread starter Victor Rodriguez
  • Start date Start date
V

Victor Rodriguez

Is there a way to present just the content of a page and turn off the master
page by code?

thanks,

Victor
 
In Page_PreInit you can set this.MasterPageFile = null, but if you do
that you'll get an error telling you that 'Content controls are allowed
only in content page that references master page'

So I think you're out of luck, unless you can walk the controls
heirarchy and remove the content controls.

But I'm with Mark, why would you do this?
 
I'm looking for a a way to have a page without the master in order to print
the page without all the stuff on the master. Do you have a better way for
this?

thanks,

Victor
 
Hi Victor,

What I did was create a stripped down 'printfriendly.master' page that does
away with all the regular page content.

You can hook up it up to a Print Friendly image button by passing a
querystring parameter like ?pf=1 to invoke the printer friendly master page:

protected void Page_PreInit(object sender, EventArgs e)
{
if (Request["pf"] == "1")
{
Page.MasterPageFile = "printfriendly.master";
}
}

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
 
Thanks for Ken's good suggestion.

Hi Victor,

I agree with Ken. MasterPage for ASP.NET 2.0 page is working like a
UserControl and it will load all the Content controls in concrete page when
the content page is loading at runtime. Therefore, a content page can not
be displayed individually without a MasterPage. However, as Ken mentioned,
ASP.NET 2.0 page can dynamically specify the MasterPage file in the
"PreInit" event, therefore, you can prepare a print friendly master page
and when the user click print button, directly him to a page which is
decorated with that print friendly master page. Do you think this a
workable solution?

here is blog article describing dynamic page layout through MasterPage:

#Recipe: Dynamic Site Layout and Style Personalization with ASP.NET
http://weblogs.asp.net/scottgu/archive/2006/07/22/Recipe_3A00_-Dynamic-Site-
Layout-and-Style-Personalization-with-ASP.NET--.aspx

Hope this also helps some.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
or you can use a print specific .css that hides the unwanted master page
bits using display:none; and so do away with the additional master page, the
master page selection code and the print button.
 
Sounds like a great solution to me I'll try it today.

Victor

Ken Cox said:
Hi Victor,

What I did was create a stripped down 'printfriendly.master' page that
does away with all the regular page content.

You can hook up it up to a Print Friendly image button by passing a
querystring parameter like ?pf=1 to invoke the printer friendly master
page:

protected void Page_PreInit(object sender, EventArgs e)
{
if (Request["pf"] == "1")
{
Page.MasterPageFile = "printfriendly.master";
}
}

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]


Victor Rodriguez said:
I'm looking for a a way to have a page without the master in order to
print the page without all the stuff on the master. Do you have a better
way for this?

thanks,

Victor
 
Thanks for your help, one more thing, is it possible to have this routine on
a handler so that it could happen on any page without going to all the pages
and adding those lines of code?

Thanks again,

Victor


Ken Cox said:
Hi Victor,

What I did was create a stripped down 'printfriendly.master' page that
does away with all the regular page content.

You can hook up it up to a Print Friendly image button by passing a
querystring parameter like ?pf=1 to invoke the printer friendly master
page:

protected void Page_PreInit(object sender, EventArgs e)
{
if (Request["pf"] == "1")
{
Page.MasterPageFile = "printfriendly.master";
}
}

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]


Victor Rodriguez said:
I'm looking for a a way to have a page without the master in order to
print the page without all the stuff on the master. Do you have a better
way for this?

thanks,

Victor
 
Hi Victor,

Do you mean you want to put the master page selecting code into a central
place instead of spreading it in each content page? So far I can not get
any idea on using a non-page specific event handler, what I can get is
defining a base page class and override the "OnPreInit" method and
programmtically assign the "MasterPageFile" property in it according to
certain condition. e.g.:

===================
public class BasePage : Page
{
....................

protected override void OnPreInit(EventArgs e)
{
base.OnPreInit(e);

if (Request.QueryString["print"] == "true")
{
this.MasterPageFile = "~/Master/print.master";
}

}


}


=====================

And for our content pages which will need to apply the print friendly
master page, just derive it from our custom basepage class istead of the
default "Page" class. e.g.


===================
public partial class Concrete_printtestpage : BasePage
{
.....................
}
===============

Hope this helps.


Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead



This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top