可以“内容页面”吗? 发送简单的“属性”; 到“母版页”?
母版页的基本思想很简单——您有一个内容块,您想要将其“注入”到母版页中的某个位置。
甚至无需阅读有关母版页的文档(我承认没有阅读!),就很容易弄清楚这一点。
我想要做的是将“属性”从其子级传递到母版页。 例如,我可能有一个主内容面板,我想为其子页面中的像素设置填充。 我可能希望母版页可以使用其他简单的“原始类型”来呈现其子项。 我想尽可能避免弄乱样式表 - 否则我最终会得到大量类似名称的项目。
有没有更好的方法来做到这一点?
The basic idea of a masterpage is simple -- you have a block of content that you want to 'inject' into a location in a master page.
Its very easy to figure this out without even reading the documentation about masterpages (which I admit to not having read!).
What i want to do is pass 'properties' to a master page from its child. For instance I may have a main content panel for which i want to set the padding in pixels in the child page. There may be other simple 'primitive types' that I want available to the master page to render its children. I want to avoid messing with style sheets as much as possible - or I'll end up with a tonne of similarly named items.
Is there a prefered way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在母版页中创建某种类型的挂钩(属性或方法),允许某些代码以您想要的方式操作母版页。 然后在各个页面上执行如下操作:
无论您做什么,都不要以相反的方式做事(在母版页中创建特殊情况,在页面中搜索某些神奇的值)。 您希望提供一个接口来操作母版页,否则最终会得到非常混乱的代码。
In your master page create some type of hook (a property or method) that allows some piece of code to manipulate the master page in whatever way you want. Then on the individual pages do something like this:
Whatever you do, do NOT do things the other way around (creating special cases within the master page that search the page for some magic value). You want to provide an interface to manipulate the master page, otherwise you'll end up with very messy code eventually.
是的,但是反过来。
如果设置内容页的 MasterPageType 属性,则可以使用 Master.PropertyName 语法访问母版页的所有公共属性。
这样您的子页面就可以获取和设置母版页的属性值。
Yes, but the other way round.
If you set the MasterPageType property of your content page you can access all public properties of the master page using the Master.PropertyName syntax.
So your child page can get and set property values of the master page.