473,946 Members | 2,504 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1844
"Victor Rodriguez" <la*******@news groups.nospamwr ote in message
news:O3******** ******@TK2MSFTN GP03.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.MasterPage File = 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**********@d evelop.comwrote in message
news:eU******** *****@TK2MSFTNG P04.phx.gbl...
In Page_PreInit you can set this.MasterPage File = 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(ob ject sender, EventArgs e)
{
if (Request["pf"] == "1")
{
Page.MasterPage File = "printfriendly. master";
}
}

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
"Victor Rodriguez" <la*******@news groups.nospamwr ote in message
news:OF******** ******@TK2MSFTN GP02.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**********@d evelop.comwrote in message
news:eU******** *****@TK2MSFTNG P04.phx.gbl...
>In Page_PreInit you can set this.MasterPage File = 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.comw rote in message
news:cL******** ******@TK2MSFTN GXA01.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**********@n ewsgroups.nospa mwrote in message
news:eu******** ******@TK2MSFTN GP03.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(ob ject sender, EventArgs e)
{
if (Request["pf"] == "1")
{
Page.MasterPage File = "printfriendly. master";
}
}

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
"Victor Rodriguez" <la*******@news groups.nospamwr ote in message
news:OF******** ******@TK2MSFTN GP02.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**********@d evelop.comwrote in message
news:eU******* ******@TK2MSFTN GP04.phx.gbl...
>>In Page_PreInit you can set this.MasterPage File = 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**********@n ewsgroups.nospa mwrote in message
news:eu******** ******@TK2MSFTN GP03.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(ob ject sender, EventArgs e)
{
if (Request["pf"] == "1")
{
Page.MasterPage File = "printfriendly. master";
}
}

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
"Victor Rodriguez" <la*******@news groups.nospamwr ote in message
news:OF******** ******@TK2MSFTN GP02.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**********@d evelop.comwrote in message
news:eU******* ******@TK2MSFTN GP04.phx.gbl...
>>In Page_PreInit you can set this.MasterPage File = 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(Event Args e)
{
base.OnPreInit( e);

if (Request.QueryS tring["print"] == "true")
{
this.MasterPage File = "~/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_printt estpage : 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
1641
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
2455
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 web part page? Does it take place at the page level? ...or the content area level? 3. Where is the Web Part Manager instantiated? ...in the Master Page? ....Content Page? ...elsewhere?
20
2448
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 include files to change the layout. When I came to ASP.NET, I used user controls to do a similar thing. I have just been looking at master pages, and it looks like they do the same thing. If so, is there any advantage in using them over the...
1
1889
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 master page looks like this... <%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
17
3180
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 pages? Kinda sorta a critical point no? Am I missing something? Rob. P.S. the day I find a book that actually is useful rather than just a
7
8744
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 remain the same. I am interested to know your opinions/suggestions in finding an easy way of doing it. In asp one could have something like this:
8
6717
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 and also my first true attempt at using master pages. I tried setting up a style sheet with a simple setting to float an image to the right and it had no effect on the image. Then, I tried putting the style code in my ASPX file as such,
3
5995
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 master page, which both of these child master pages are based on, and in turn the final pages are based on one of these child master pages.
13
5328
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 (called "CurFlag") on my master page that can be accessed from content pages, but not from separate code modules. I tried doing something like this in my VB code module: Dim myMaster As MasterPage = CType(ProjectMgmt.Master, MasterPage)
6
1698
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 templates in that when the master page is updated, all the child pages created from the master page are updated and then they all need to be uploaded to the server? Or do you only have to upload the master page after an update?
0
9982
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11566
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9886
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8253
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7427
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6331
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4943
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4533
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3541
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.