[英]Is it inefficient to use ASP web forms controls for every HTML tag on a web page?
Should I be using tags (or literal tags) for every piece of content on my page (h tags, p tags, etc.)? 我应该为页面上的每个内容使用标签(或文字标签)(h标签,p标签等)吗? Even if it is not dynamic. 即使它不是动态的。 Or is this considered to be inefficient having the server process all this content? 或者,如果服务器处理所有这些内容,这被认为效率低下?
No, you should not use server tags for static content on your page that does not need it. 不,您不应将服务器标签用于页面上不需要它的静态内容。
Every servers-side tag you add to your ASP.Net web page (ie every tag that has a runat="Server" attribute) adds extra processing to your page. 您添加到ASP.Net网页的每个服务器端标记(即每个具有runat =“Server”属性的标记)都会为您的页面添加额外的处理。 For each server tag, ASP.Net adds information to viewstate, which must then be serialized and sent across the wire for each request. 对于每个服务器标签,ASP.Net将信息添加到viewstate,然后必须将其序列化并通过线路发送每个请求。 In addition, when the page is processed and rendered on the server, the ASP.Net pipeline must instantiate these server-side tags and re-hydrate their properties from viewstate. 此外,当在服务器上处理和呈现页面时,ASP.Net管道必须实例化这些服务器端标记并从viewstate重新保持其属性。 All of this adds overhead to a request processing. 所有这些都增加了请求处理的开销。
So for basic HTML tags that do not require persistance of server-side state or do not require the advanced functionality of ASP.Net web forms or HTML controls, do not use server-side tags. 因此,对于不需要服务器端状态持久性或不需要ASP.Net Web表单或HTML控件的高级功能的基本HTML标记,请不要使用服务器端标记。 Just use the basic HTML tags (ie H1, P, etc) without the runat="server" attribute. 只需使用没有runat =“server”属性的基本HTML标记(即H1,P等)。
For more information on the ASP.Net page lifecycle, see here . 有关ASP.Net页面生命周期的更多信息,请参见此处 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.