设置一个ASP.NET母版页在运行时母版、ASP、NET

2023-09-03 09:46:16 作者:北城诀、回眸三生琥珀色ら

我工作的一个网站,需要能够支持两个或两个以上的外观,多变的运行。我很希望能够处理使用CSS开关的变化,但它看起来像我需要使用不同的母版为每个设计。

I'm working on a site which needs to be able to support two or more looks, changable at runtime. I'd hoped to be able to handle the change with a CSS switch, but it looks like I'll need to use a different masterpage for each design.

那么,有什么要设置的母版在运行时的最佳方式是什么? Page.MasterPageFile只能在Page.On preINIT事件设置。它看起来像解决方案,使我的所有网页,从它处理preINIT事件,或使用一个HTTP模块这确实是一个共同的基础继承。

So, what's the best way to set the masterpage at runtime? Page.MasterPageFile can only be set in the Page.OnPreInit event. It looks like the solutions are to make all my pages inherit from a common base which handles the PreInit event, or to use an HttpModule which does that.

任何意见?

推荐答案

我做这个前一次,我没有你描述的到底是什么(所做的所有页从自定义页面继承与在preINIT事件)。另外我有一个自定义的Application_ preRequestHandlerExecute在我的Global.asax.cs设置Page.StyleSheetTheme这样做,并不需要一个不同的母版页图像/ CSS的变化。

I've done this once before, I did exactly what you described (Made all pages inherit from a custom page with an OnPreInit event). Also I had a custom Application_PreRequestHandlerExecute in my Global.asax.cs for setting Page.StyleSheetTheme for doing image/css changes that didn't require a different Master Page.