问题描述
我喜欢HtmlControls因为没有HTML魔法回事... ASP源看起来类似于客户端看到的东西。
I like HtmlControls because there is no HTML magic going on... the asp source looks similar to what the client sees.
我无法与GridView控件,直放站,CheckBoxLists等实用争论,所以我用他们,当我需要的功能。
I can't argue with the utility of GridView, Repeater, CheckBoxLists, etc, so I use them when I need that functionality.
此外,它看起来怪异有code的混合和匹配:
Also, it looks weird to have code that mixes and matches:
<asp:Button id='btnOK' runat='server' Text='OK' />
<input id='btnCancel' runat='server' type='button' value='Cancel' />
(在你想一个服务器端的事件监听器绑定到确定的,但取消该事件的上述情况只是运行,隐藏当前的div一个JavaScript)
(The above case in the event you wanted to bind a server-side event listener to OK but Cancel just runs a javascript that hides the current div)
有一些明确的风格指南在那里?应该HtmlControls只是避免?
Is there some definitive style guide out there? Should HtmlControls just be avoided?
推荐答案
这可能是当你想在那结束了你的网页越来越发出的标记了更多的控制权觉得HTML控件作为一个选项很有用。更多的控制,你希望每一个浏览器中看到一模一样的标记感。
It might be useful to think of HTML controls as an option when you want more control over the mark up that ends up getting emitted by your page. More control in the sense that you want EVERY browser to see exactly the same markup.
如果你创建了System.Web.UI.HtmlControls:
If you create System.Web.UI.HtmlControls like:
<input id='btnCancel' runat='server' type='button' value='Cancel' />
然后,你知道什么样的code的将是射出。尽管大多数时间:
Then you know what kind of code is going to be emitted. Even though most of the time:
<asp:Button id='btnCancel' runat='server' Text='Cancel' />
最终会被相同的标记。相同的标记并不总是发出的所有器WebControls。许多器WebControls已经内置了自适应渲染,将呈现基于浏览器的用户代理不同的HTML。作为一个例子一个DataGrid看起来在移动浏览器比它会完全不同的桌面浏览器。
will end up being the same markup. The same markup is not always emitted for all WebControls. Many WebControls have built in adaptive rendering that will render different HTML based on the browser user agent. As an example a DataGrid will look quite different in a mobile browser than it will in a desktop browser.
使用器WebControls而不是HtmlControls也让你可以充分利用 ASP.NET 2.0 ControlAdapters的一>,我相信只能用器WebControls的作品,这将允许你在说时发出的标记程序化配置驱动的控制。
Using WebControls as opposed to HtmlControls also lets you take advantage of ASP.NET v2.0 ControlAdapters which I believe only works with WebControls, this will allow you programatic config driven control over the markup that gets emitted.
当你考虑到某些移动浏览器或WebTVs会想加价的WML或完全不同的集这似乎更有价值。
This might seem more valuable when you consider that certain mobile browsers or WebTVs are going to want WML or completely different sets of markups.
这篇关于何时使用HtmlControls VS器WebControls的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!