简体   繁体   中英

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.)? 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. For each server tag, ASP.Net adds information to viewstate, which must then be serialized and sent across the wire for each request. 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. 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. Just use the basic HTML tags (ie H1, P, etc) without the runat="server" attribute.

For more information on the ASP.Net page lifecycle, see here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM