ASP.NET MVC 1.0 嵌套母版页
我的母版页有问题。它们具有这样的继承顺序:
MainMaster1.Master 可以嵌套 Nested1.Master、Nested2.Master 等。 同时 MainMaster 可以复制并具有工作副本,如 MainMaster2、MainMaster3 等。
请问我如何动态更改 Nested1、Nested2 等页面的 MasterPageFile,以便它们可以在需要时轻松在 MainMaster 之间切换?
我尝试在嵌套母版的 Page_PreInit 中处理该问题,但无法让它进入此事件处理程序。我还尝试更改嵌套的“protected void OnPreInit”中的主控,但结果是相同的。
谢谢,
罗曼。
I have a problem with my master pages. They have such inheritance order:
MainMaster1.Master can be nested by Nested1.Master, Nested2.Master, etc.
At the same time MainMaster can be duplicated and have working copies like MainMaster2, MainMaster3, etc.
Advise please how can I dynamically change the MasterPageFile of my Nested1, Nested2, etc. pages so that they can easily switch between MainMasters if needed?
I tried to treat the problem in Page_PreInit of the nested masters but couldn't get it entering this event handler. I also tried to change the masters in "protected void OnPreInit" of nested ones but result was the same.
Thanks,
Roman.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅以下文章,了解您可以使用的几种可能的技术:
在 ASP.NET MVC 中的母版页之间动态切换 http://www.codeofrob.com/archive/2009/11/01/dynamically-switching -master-pages-in-asp.net-mvc.aspx之间
See the following article for several possible techniques you can use:
Dynamically Switching between Master Pages in ASP.NET MVC http://www.codeofrob.com/archive/2009/11/01/dynamically-switching-between-master-pages-in-asp.net-mvc.aspx
我认为这仍然是他的意思,尽管它没有直接回答问题。
Page 有一个名为 MasterPageFile 的属性,上面的文章中使用了该属性
Page 也有一个名为 MasterPage 的属性
在 MasterPage 上,有一个名为 MasterPageFile 的属性(如上面的文章)
MasterPage 还有一个名为 MasterPage 的属性,
虽然该页面上的示例涵盖了直接更改页面上的母版页,但您可以通过递归母版页来查找和更改您想要的母版页,从而执行与母版页本身非常相似的操作。
我希望这有帮助。
I think that's still what he meant, although it doesn't directly answer the question.
Page has a property called MasterPageFile which is used in the above article
Page also has a property called MasterPage
On MasterPage, there is a property called MasterPageFile (As in the above article)
MasterPage also has a property called MasterPage
While the example on that page covers with changing the master page on the page directly, you can do very much similar to the master page itself by recursing up through the master pages to find and change the one you want.
I hope that helps.