asp.net 2.0 Master Page

S

sck10

Hello,

Currently I am using the following:
<%@ Page Language="VB" StylesheetTheme="Default"
MasterPageFile="~/template/mpColumn02.master" CodeFile="custrev.aspx.vb"
Inherits="custrev" title="Untitled Page" Trace="false" %>

Is there any way to pragmatically change the MasterPageFile? I need to
create a printer friendly link. With the link changing the MasterPageFile
from MasterPageFile01 to MasterPageFile02. Any help with this would be
appreciated...
 
K

Ken Cox [Microsoft MVP]

Hi,

What I do is pass a querystring value to indicate that the user has clicked
the print-friendly link. I detect that in the pre_init event and change the
master there. Here's some VB code:

Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As
System.EventArgs)
If Request("pr") = "1" Then
Me.Page.MasterPageFile = "print.master"
End If
End Sub


Here's a C# version:

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

Does this help?

Ken
Microsoft MVP [ASP.NET]
 
S

sck10

Thanks Ken,

Works great...



Ken Cox said:
Hi,

What I do is pass a querystring value to indicate that the user has
clicked the print-friendly link. I detect that in the pre_init event and
change the master there. Here's some VB code:

Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As
System.EventArgs)
If Request("pr") = "1" Then
Me.Page.MasterPageFile = "print.master"
End If
End Sub


Here's a C# version:

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

Does this help?

Ken
Microsoft MVP [ASP.NET]


sck10 said:
Hello,

Currently I am using the following:
<%@ Page Language="VB" StylesheetTheme="Default"
MasterPageFile="~/template/mpColumn02.master" CodeFile="custrev.aspx.vb"
Inherits="custrev" title="Untitled Page" Trace="false" %>

Is there any way to pragmatically change the MasterPageFile? I need to
create a printer friendly link. With the link changing the
MasterPageFile from MasterPageFile01 to MasterPageFile02. Any help with
this would be appreciated...
 
A

Alan Silver

sck10 said:
I need to create a printer friendly link

In that case you would be far better off learning CSS and writing a
stylesheet that formats the page for a printer. The idea of having a
separate "printer friendly" version of a page went out years ago.
There's no reason to do it nowadays.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top