如果不针对特定浏览器进行呈现,为什么要使用适配器来扩展 ASP.Net 控件呢?
我对控制适配器的理解是,它们被设计为允许不同的浏览器呈现不同的 HTML(因此,您将它们注册在 .browsers 文件中...)。
然而,人们似乎只是为默认浏览器注册适配器,并使用它们来覆盖 ASP.Net 控件的 Render 方法。
你相信这是真的吗? 如果是这样,为什么不直接从控件继承并以这种方式重写 Render 方法,而不是使用适配器?
覆盖的好处是您可以向其添加更多属性,而适配器则无法做到这一点。
我只是想确保我没有错过一些使适配器比覆盖更好的秘密武器。
My understand of Control Adapters is that they're designed to allow different HTML rendering for different browsers (thus, you register them in the .browsers file...).
However, it appears people are just registering adapters for the default browser and are using them to generally override the Render method of ASP.Net controls.
Do you believe this is true? If so, why wouldn't you just inherit from a control and override the Render method that way, rather than use an adapter?
A benefit of overriding is that you can add more properties to it, which you can't do with adapters.
I just want to make sure I'm not missing some secret sauce that makes adapters better than overriding.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,为默认浏览器注册适配器是很常见的。 这背后的主要思想是覆盖现有控件的渲染功能。 例如,所谓的 'Css 友好'控件适配器 - 这项工作主要是为了使控件产生更多符合标准的 html。
基本上,您在这里缺少的是,您可以在使用标准 asp.net 控件的现有站点上删除一组针对默认浏览器的控件适配器,并获得“更好”或“不同”的标记,而无需更改您的站点使用您创建的自定义控件。
Yes, it's quite common to register adapters for the default browser. The main idea behind this is to override the rendering functionality for existing controls. E.g. The so called 'Css Friendly' control adapters - this effort was largely to make the controls produce more standards compliant html.
Basically the thing you are missing here is that you can drop a set of control adapters aimed at the default browser on an existing site that uses the standard asp.net controls and get 'better' or 'different' markup without having to change your site to use custom controls that you have created.