何时使用RUNAT ="服务器"在普通的HTML

编程入门 行业动态 更新时间:2024-10-26 10:27:04
本文介绍了何时使用RUNAT ="服务器"在普通的HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

是以往任何时候都适合到一个标准的HTML元素,而不是一个真正的ASP.NET控件上使用=服务器?我有超过设定标准元素的HTML /文本完全控制,所以我为什么不使用它,而不是一个笨重ASP.NET WebForms的控制?

如果其中一个比其他更好的,一些感兴趣的点,我想知道:

  • 性能差异
  • 功能差异
  • 其他差异不那么明显?

一个例子不同之处:

< ASP:文字ID =mySpecialHtml=服务器/>< D​​IV 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

本文发布于:2023-06-08 03:56:39,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/576194.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:服务器   RUNAT   QUOT   HTML

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!