何时使用RUNAT ="服务器"在普通的HTML [英] When to use runat="server" on normal HTML
问题描述
是以往任何时候都适合到一个标准的HTML元素,而不是一个真正的ASP.NET控件上使用=服务器?我有超过设定标准元素的HTML /文本完全控制,所以我为什么不使用它,而不是一个笨重ASP.NET WebForms的控制?
如果其中一个比其他更好的,一些感兴趣的点,我想知道:
- 性能差异
- 功能差异
- 其他差异不那么明显?
一个例子不同之处:
< ASP:文字ID =mySpecialHtml=服务器/>< DIV ID =mySpecialHtml=服务器/>
两者都是ASP.NET服务器控件。对应的HTML元素的是在 System.Web.UI.HtmlControls
命名空间,而Web控件位于的System.Web.UI。器WebControls
命名空间。
HTML控件更重量轻,正好对应一个HTML元素,而Web控件有更多的功能,并且可以呈现为视浏览器的功能不同的HTML元素和控件的设置。
一个HTML控件呈现为一个HTML元素,而Web控件呈现为零个或多个HTML元素。例如,文字
控件不呈现为一个元素,它只能输出其文本。有迹象表明,不会单独提供任何元素其他控件,如转发
和占位符
控制。在另一方面,例如的CheckBoxList
控件呈现几个HTML元素,表
集装箱和输入
元素里面每个复选框。
这是利用不同的元素呈现的控制的一个例子是文本框
控制,这将呈现无论是作为输入
或的textarea
取决于其的TextMode
属性。元素
在Web控件有更多的功能,而且还采用了更多的资源。他们有更多的特性和支持之类的主题和数据绑定。许多Web控件放在的ViewState
,它被作为页面的一部分数据。如果你不小心,的ViewState
可以得到相当大,影响页面的加载时间。
Is it ever appropriate to use runat="server" on a standard HTML element instead of a true ASP.NET control? I have full control over setting the html/text of the normal element, so why wouldn't I use it instead of a "clunky" ASP.NET WebForms control?
If one is better than the other, some points of interest I would like to know:
- Performance differences
- Functionality differences
- Other differences not so obvious?
An example difference:
<asp:Literal ID="mySpecialHtml" runat="server" />
<div id="mySpecialHtml" runat="server" />
Both are ASP.NET server controls. The ones corresponding to HTML elements are in the System.Web.UI.HtmlControls
namespace, and the web controls are in the System.Web.UI.WebControls
namespace.
The HTML controls are more light-weight and correspond exactly to an HTML element, while the web controls have more features and can be rendered as different HTML elements depending on the browser capabilities and the settings of the control.
A HTML control renders as a single HTML element, while a web control is rendered as zero or more HTML elements. The Literal
control for example isn't rendered as an element, it only outputs its text. There are other controls that doesn't render any elements by themselves, like the Repeater
and PlaceHolder
controls. On the other hand, the CheckBoxList
control for example is rendered as several HTML element, a table
as container, and input
elements for each checkbox inside it.
An example of a control that is rendered using different elements is the TextBox
control, which will be rendered either as an input
or a textarea
element depending on its TextMode
property.
The web controls have more features, but also uses more resources. They have more properties and support things like themes and data binding. Many of the web controls put data in the ViewState
, which is sent as part of the page. If you are not careful, the ViewState
can get quite large, and affect the loading time of the page.
这篇关于何时使用RUNAT =&QUOT;服务器&QUOT;在普通的HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!