设置一个ASP.NET母版页在运行时 [英] Setting an ASP.NET Master Page at runtime

查看:166
本文介绍了设置一个ASP.NET母版页在运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个网站,需要能够支持两个或两个以上的外观,多变的运行。我很希望能够处理使用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.

这篇关于设置一个ASP.NET母版页在运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆