ASP.NET嵌套母版页,如何从aspx文件设置首页内容?
我有一些来自 CMS 的内容,需要将其移至原始 asp.net 页面。由于模板是嵌套的,我想我可以使用嵌套母版页来完成它,但我发现我无法从深层子页面在顶部母版页上设置值。
这是一个示例。我有几个带有 contentplaceholders 的嵌套母版页:
- 顶级母版(带有 contentPlaceHolder1)
- 嵌套母版,依赖于顶级母版(带有 contentPlaceHolder2)
- aspx 页面,依赖于嵌套母版,定义 contentPlaceHolder1 和 2 的内容
问题是 asp.net 不允许我要在内容页面中定义 contentPlaceHolder1 的值,它应该在嵌套母版中定义。但关键是客户端页面知道该值,而不是模板母版(例如,页面知道它必须在顶部显示的图形,但该图形的占位符是顶部母版)。
如何设置要在顶级母版中呈现的 aspx 页面中的值?
I have some content from a CMS that I need to move to raw asp.net pages. Since the templates are nested I guess I can use nested masterpages to acomplish it, but I'm finding that I can't set values on the top masterpage from the deep child page.
Here is a sample. I have several nested masterpages with contentplaceholders:
- top master (with contentPlaceHolder1)
- nested master, dependent on top master (with contentPlaceHolder2)
- aspx page, dependent on nested master, defines content for contentPlaceHolder1 and 2
The problem is that asp.net doesn't allow me to have the value of contentPlaceHolder1 defined in the content page, it should be defined in the nested master. But the point is that the client page knows that value, not the template masters (for instance, the page knows about the graphic it has to display on the the top, but the placeholder for the graphic is the top master).
How can I set values in the aspx page to be rendered in the top master?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通常,您必须执行以下操作:
Master.YourPageProperty = "value ";
在嵌套母版页的情况下,您还必须使用上述相同方法设置传递公共属性,但在嵌套母版页中执行此操作(即定义嵌套母版页母版页并设置虚拟公共属性只需将传入嵌套主控的值设置为顶级主控)。
尝试查看这篇文章以强化我所触及的想法:
Normally you would have to do the following:
Master.YourPageProperty = "value";
In the case of nested masterpages you must also setup pass-through public properties using the same method above but doing it in your nested master page (ie define the nested master pages master page and set up dummy public properties that just set the value passed in to the nested master to the top master).
Try looking at this article to reinforce the ideas I have touched upon:
我通常使所有 .aspx 页面继承自基页面,并在此页面上为我想要共享的任何数据设置属性。然后,在顶部母版页上,您可以将当前页面转换为类型基本页面,然后可以访问所有数据。
我通常也会将基页公开为我的母版页上的属性,这样,如果我遇到不从我的基页继承的页面正在使用母版页的情况,我可以进行软转换并进行空检查。
I normally make all of my .aspx pages inherit from a base page, and on this page I set up properties for any data that I want to share. Then, on your top master page you can cast the current page to type basepage and then have access to all the data.
I usually expose the base page as a property on my master page also, that way I can do a soft cast and do null checking if I have any case where a page that doesn't inherit from my base page is using the master page.