473,387 Members | 1,619 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,387 software developers and data experts.

Loading MasterPage form database

Hi,

I'm currently loading my masterpage from a file via an httpmodule.

How can I modify this code to load the masterpage from a database? Is
the only way to save the file to a temp file first and load via
page.MasterPageFile?

Thanks,

Paul.

using System;
using System.Web;
using System.Web.UI;

public class MasterPageModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new
EventHandler(context_PreRequestHandlerExecute);
}

void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
Page page = HttpContext.Current.CurrentHandler as Page;
if (page != null)
{
page.PreInit += new EventHandler(page_PreInit);
}
}

void page_PreInit(object sender, EventArgs e)
{
Page page = sender as Page;
if (page != null)
{
page.MasterPageFile = "~/MasterPage.master";
}
}

public void Dispose()
{
}
}

Dec 5 '06 #1
4 2117
yes, you have to write to a temp file, so the the aspnet_compiler can
see it.

-- bruce (sqlwork.com)

pa******@hotmail.com wrote:
Hi,

I'm currently loading my masterpage from a file via an httpmodule.

How can I modify this code to load the masterpage from a database? Is
the only way to save the file to a temp file first and load via
page.MasterPageFile?

Thanks,

Paul.

using System;
using System.Web;
using System.Web.UI;

public class MasterPageModule : IHttpModule
{
public void Init(HttpApplication context)
{
context.PreRequestHandlerExecute += new
EventHandler(context_PreRequestHandlerExecute);
}

void context_PreRequestHandlerExecute(object sender, EventArgs e)
{
Page page = HttpContext.Current.CurrentHandler as Page;
if (page != null)
{
page.PreInit += new EventHandler(page_PreInit);
}
}

void page_PreInit(object sender, EventArgs e)
{
Page page = sender as Page;
if (page != null)
{
page.MasterPageFile = "~/MasterPage.master";
}
}

public void Dispose()
{
}
}
Dec 5 '06 #2
<pa******@hotmail.comwrote in message
news:11**********************@79g2000cws.googlegro ups.com...
How can I modify this code to load the masterpage from a database? Is
the only way to save the file to a temp file first and load via
page.MasterPageFile?
In addition to what Bruce said, a MasterPage by definition is going to get
called probably more than all the other pages in your app combined, so what
you're proposing to do is likely to be extremely inefficient in terms of
performance and resources.

Is there a specific reason you need to do this? MasterPages are very
flexible and quite easily programmable...
Dec 5 '06 #3
It's just a requirement that my app will have a large number of
MasterPages (hundreds of clients, each with their own visual identity).
I understand what was said about performance but it would have been
nice to be given the option of, say, reading from db, storing to cache
and then subsequently loading from cache.

However, temp files are pretty straightforward though so shouldn't be a
problem.

Thanks for all you help,

Paul.

Dec 5 '06 #4
<pa******@hotmail.comwrote in message
news:11**********************@79g2000cws.googlegro ups.com...
It's just a requirement that my app will have a large number of
MasterPages (hundreds of clients, each with their own visual identity).
I have exactly the same requirement. Each client has their own MasterPage,
which I set when the site loads.

Go here: http://www.inthecage.co.uk and click the "Log in" button in the top
right-hand corner.

Now go here: http://www.sanctuaryrig.co.uk, enter the site, and click the
"Log in" button in the top right-hand corner.

Of course, it's exactly the same secure site, just with a different
MasterPage. No need for reading from a database, creating a temporary file
etc...
I understand what was said about performance but it would have been
nice to be given the option of, say, reading from db, storing to cache
and then subsequently loading from cache.
Again, there simply is no need whatsoever to do this...
However, temp files are pretty straightforward though so shouldn't be a
problem.
I see.
Dec 5 '06 #5

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

Similar topics

2
by: dawg1998 | last post by:
I have a page that creates dynamic textboxes based on the number of fields a user chooses to fill out. This process worked great when the page was standalone. However, when I move to a...
4
by: Alex Maghen | last post by:
I have a master page which contains a general page framework and also contains a <form runat=server> around most of the content of the page. Inside that <form> tag is a ContentPlaceholder. I...
5
by: Cenk Genisol | last post by:
Hi NG, I am relatively new to Web developement and have some questions to you. I've got a Masterpage where some graphics are embedded by CSS. They format the borders of tables, which store...
6
by: =?Utf-8?B?QmVuIFIu?= | last post by:
Hi, WHen I specify my master page in the page's @Page directive, no problems. However, when I put it ias an attribute in Web.config's page element, the designer fails. It just says "Error...
7
by: Bon | last post by:
Dear all I create a master page with image buttons on the left-hand side for navigation. When a user clicks the student button, the content (i.e. ContentPlaceholder) in masterpage will be...
8
by: Randy Smith | last post by:
Hi, I now need to add MasterPages to a number of existing forms, but when I add the code for MasterPage, the MasterPage does NOT appear when it runs. Any thoughts? TIA, Randy Smith
0
by: dixonjm | last post by:
Hi, I have a master page & various pages that will use this master page. Each content page will have a CSS & JS file which will be named the same as the content page. When I try to load the CSS...
2
by: =?Utf-8?B?QWxleCBNYWdoZW4=?= | last post by:
I have a MasterPage. The MasterPage actually contains the <formtag which is used throughout the site. On just certain pages that use that MasterPage, I need the "enctype" for the <formtag to be...
4
by: =?Utf-8?B?SmFwZQ==?= | last post by:
Can I refer to the controls on default.aspx from the masterpage? I have a form on the masterpage which sends information that is in a gridview in the default.aspx page.
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...

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.