以编程方式更改母版页 [英] Changing Master Pages Programatically

查看:105
本文介绍了以编程方式更改母版页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个包含2个母版页的Web应用程序.我的客户希望每月更改一次Web应用程序的外观.为此,我又创建了2个具有不同外观的母版页.我面临的问题是动态更改母版页.我必须选择的一个方法是在应用程序每个页面的Page_PreInit()中进行更改,但是该应用程序大约有200个网页.有没有其他更优雅的方法可以实现这一目标?

Hi,

I have a web application with 2 master pages in it. My client wants to change look of the web application each month. For that purpose I created 2 more master pages with different look and feel. The problem I am facing is changing master pages dynamically. One option I have is to change it in Page_PreInit () of each page of the application but the application has around 200 web pages. Is there any other more elegant way to achieve this ?

推荐答案

是的,有一种方法可以做到这一点.但我想知道为什么您需要两个母版页.还不够吗?如果要更改外观,最好使用CSS而不是母版页.无论如何,这是解决方案.

而不是将代码放置在每个页面的PreInit()事件中,而是将相同的代码放置到母版页的PreInit()事件中.这是MSDN文章如何执行此操作. -us/library/c8y19k6h.aspx>以编程方式使用ASP.NET母版页 [ ^ ]

希望对您有帮助.
Yes, there is a way to do that. But I wonder why you need two master pages. Isn''t one enough for you ? If you create to change the look and feel, It is better to play with CSS, Not master page.Anyways, Here is the solution.

Instead of putting code in each page PreInit() event, Put the same code to the master page PreInit() event.Here is MSDN article how to do this.Working with ASP.NET Master Pages Programmatically[^]

I hope this helps you well.


这篇关于以编程方式更改母版页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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