母版页是正确的选择吗?
我可能疯了,但母版页让我害怕,因为我担心一旦我被锁定使用母版页,我会遇到一种情况,我只想继承母版页 90% 的视觉内容,迫使我打破了继承,因此必须复制母体中的内容并将其带入孩子体内。
我觉得这是任何类型的“继承”的问题,因为你必须小心,但似乎至少你可以重写常规类中的方法。
我在这里可能不太连贯,但用户控件似乎为您提供了更大的灵活性。唯一的缺点是您必须将它们拖到网络表单上。对此,我说有什么大不了的。
将我的应用程序从使用用户控件转换为母版页让我感到害怕,我担心我的 Javascript 会崩溃。
评论?
I may be nuts, but master pages scare me because I fear that once I am locked into using a master page, I will encounter a situation where I will want to inherit only 90% of the visual content of the master page, forcing me to break the inheritance and thus having to reproduce the content that was in the master and bring it into the child.
I sense that this is a problem with any kind of "inheritance" in that you have to be careful, but it seems that at least you can override methods in a regular class.
I'm probably not too coherent here, but user controls seem to give you more flexibility. The only draw back is that you have to drag them onto a webform. To that, I say big deal.
Converting my app from using usercontrols to master pages is scaring me and I am afraid that my Javascript will break.
Comments?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
别害怕。
您可以根据需要创建任意数量的占位符,使您的母版页非常精细。这些占位符还可以包含默认内容和内容。控制。
因此,在 90% 想要默认标记的页面中,您可以省略覆盖内容。
或者,在 10% 的情况下,您想要不同的东西,您可以提供覆盖标记
示例:
在您的主页上,您可以有一个像这样的页面:
在所有其他页面上,通过省略标题标签来利用默认的“标题”像这样:
Don't be scared.
You can create as many placeholders as you like, making your master page very granular. These placeholders can also contain default content & controls.
Therefore in the 90% of pages where you want the default markup you can omit the overriding content.
Alternatively in the 10% of cases where you want something different you can supply overriding markup
Example:
on your homepage you could have a page like so:
on all your other pages take advantage of the default 'Headline' by omitting the tag for the headline like so:
我不会考虑不使用母版页。如果您想在大多数页面上共享大部分镶边、在筒仓中共享内部镶边等,您始终可以嵌套母版页。
I wouldn't consider not using master pages. You can always nest master pages if you want to share the out most chrome on most pages, inner chrome to share in a silo etc.
正如您提到的,继承问题可能从任何地方出现。不要过早过度设计。
对于您描述的母版页问题,您可以换入/换出不同的 css 文件,并使用选择器隐藏/更改从母版页生成的 html 部分。
Like you mentioned, inheritance problems can appear from anywhere. Don't over engineer early.
With the masterpages problem you describe, you can swap in/out different css files and use selectors to hide/change parts of the html that is generated from the masterpage.
一旦您习惯了它们,您就会开始按预期使用它们。由足够多的页面共享以保证公共源的信息(参考 CSS、通用 js、页面布局问题等)将出现在那里,稍后您会很高兴它们在那里。
当您构建一个脱离此的页面时,您可能会发现自己在 main.master 上做了一些调整(以不同的方式抽象事物),但您将能够快速进行调整并继续前进。
如果只是一个一次性页面违反了规则,那么您可以简单地告诉该页面继承不同的母版。
然而,在开始依赖它之前,先创建一个测试站点并尝试一下这个概念。
Once you're used to them, you'll start using them as intended. That information (refs to CSS,common js, page placement concerns, etc.) that is shared by enough pages to warrant a common source will go there, and you'll be happy later that they are there.
When you build out a page that breaks from that, you may find yourself doing a little adjusting back at your main.master (abstracting things differently), but you'll be able to make the adjustment fast and move forward.
If it's just a one-off page that breaks the rules, then you can simply tell that page to inherit a different master.
Make a test site and play around with the concept a bit before you start relying on it however.
母版页背后的想法很好(如果不是微不足道的话),但它是无用的,因为它们的实现。
母版页不会调用页面(内容),而是相反。那么,它有什么问题呢?很简单,你不能调用不同的页面,只能调用一个页面。因此,您正在编码并将所有代码放在同一页面中。这根本就是无稽之谈。母版页允许多个内容块,但都指向同一页面(因此,代码变得混乱)。
连接Master Page代码和调用者Page并不简单,例如,它们共享相同的“form”标签,但您必须将表单标签在您的页面中,并且您只能使用表单标签一次。 :-?
变量/值不直接共享,您可以,但它需要一些“黑客”(例如调用主函数内部的函数)
在加载周期中(页面加载之前)必须注意。
如果您的母版页是静态的,母版页就很好,否则最好在每个页面中简单地“复制和粘贴”或使用自定义控件,因为<母版页增加了新的复杂性。
请记住,母版页的目标是节省时间,如果它在此任务中失败,那么它就没用了。
我的2美分。
The idea behind master page is nice (if not trivial) but it is useless because their realization.
the master page does not call the page (content) but the opposite. So,what's the problem with it?. Simple, you can't call different pages but a single page. So, you are coding and putting all your code in the same page. It is a nonsense at all. Master page allow several content block but all point to the same page (hence, cluttering the code).
It is not trivial to connect the Master Page code and the caller Page, for example, they share the same "form" tag, but you must put the form tag in your page and you can use the form tag only once. :-?
Variables/Values are not shared directly, you can but it require some "hack" (calling a function inside the master for example)
You must pay attention in the loading cycle (before the page load ).
Master Pages are nice, if your master page is static, otherwise it is way better to simple "copy & paste" in every page or to use custom controls, because master pages add a new level of complexity.
Remember than the goal of Master Page is to save time, if it fails in this task then, it is useless.
my 2 cents.