473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

master pages

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

thanks,

Victor
Aug 22 '06 #1
9 1810
"Victor Rodriguez" <la*******@newsgroups.nospamwrote in message
news:O3**************@TK2MSFTNGP03.phx.gbl...
Is there a way to present just the content of a page and turn off the
master page by code?
What on earth are you trying to do...???
Aug 22 '06 #2
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?

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

thanks,

Victor

Aug 22 '06 #3
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
"Kevin Jones" <kj**********@develop.comwrote in message
news:eU*************@TK2MSFTNGP04.phx.gbl...
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?

Victor Rodriguez wrote:
>Is there a way to present just the content of a page and turn off the
master page by code?

thanks,

Victor
Aug 22 '06 #4
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" <la*******@newsgroups.nospamwrote in message
news:OF**************@TK2MSFTNGP02.phx.gbl...
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
"Kevin Jones" <kj**********@develop.comwrote in message
news:eU*************@TK2MSFTNGP04.phx.gbl...
>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?

Victor Rodriguez wrote:
>>Is there a way to present just the content of a page and turn off the
master page by code?

thanks,

Victor

Aug 22 '06 #5
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/archi...-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.

Aug 23 '06 #6
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.
"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:cL**************@TK2MSFTNGXA01.phx.gbl...
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/archi...-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.
>


Aug 23 '06 #7
Sounds like a great solution to me I'll try it today.

Victor

"Ken Cox [Microsoft MVP]" <BA**********@newsgroups.nospamwrote in message
news:eu**************@TK2MSFTNGP03.phx.gbl...
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" <la*******@newsgroups.nospamwrote in message
news:OF**************@TK2MSFTNGP02.phx.gbl...
>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
"Kevin Jones" <kj**********@develop.comwrote in message
news:eU*************@TK2MSFTNGP04.phx.gbl...
>>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?

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

thanks,

Victor


Aug 23 '06 #8
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 [Microsoft MVP]" <BA**********@newsgroups.nospamwrote in message
news:eu**************@TK2MSFTNGP03.phx.gbl...
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" <la*******@newsgroups.nospamwrote in message
news:OF**************@TK2MSFTNGP02.phx.gbl...
>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
"Kevin Jones" <kj**********@develop.comwrote in message
news:eU*************@TK2MSFTNGP04.phx.gbl...
>>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?

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

thanks,

Victor


Aug 23 '06 #9
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.
Aug 24 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sasha | last post by:
Hi all asp.net proffesionals out there, How do you implement master pages in your applications? What libraries do you use and what have been your experience? Sasha
5
by: Michael Herman \(Parallelspace\) | last post by:
1. What are some compelling solutions for using Master/Content pages with Web Pages? 2. If a content area has a web part zone with web parts, what is the user experience like when "editting" the...
20
by: Alan Silver | last post by:
Hello, In classic ASP, I used to use two include files on each page, one before and one after the main content, to provide a consistent layout across a web site. That way I could just change the...
1
by: Alan Silver | last post by:
Hello, I am just experimenting with master pages, and am trying to add a content placeholder in the <head> section, so that individual pages can set their own page title and meta tags. The...
17
by: Rob R. Ainscough | last post by:
Again another simple concept that appears NOT to be intuitive or I'm just stupid. I've read the WROX book and the example doesn't actually show how the .master page links in the other content...
7
by: xkeops | last post by:
Thinking of creating a website, most of the pages will have a general toolbar menu, a content and a footer. The content will be the only one who's gonna change but the rest (header,footer) will...
8
by: JT | last post by:
Hi, I have done a fair amount of style editing inline in ASP. I'm now using VS 2005 with a standard web project (not Web Application Project). This is my first foray into CSS in a style sheet...
3
by: Rich | last post by:
Hi, I want to use 2 master pages, one for the main part of the site, the other for the admin pages. They are quite similar, with many shared elements. Ideally I would like to have a parent...
13
by: Kirk | last post by:
I have been reading Scott Allen's article on Master Pages (http:// odetocode.com/Articles/450.aspx) but I am having problems understanding a concept. Specifically, I have created a property...
6
by: Mickey | last post by:
Coming from a Dreamweaver/ASP/PHP background. Planning to use Visual Studio 2008 for a website. Complete newbie question here (please be gentle!): Do master pages work similar to Dreamweaver...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.