Is there a cost to using server tags in an ASP.NET MVC view? In other words, is the a context switch when you jump out of markup and into a <% %> block and what is the penalty paid in this instance?
A:
No. the compiler converts the .aspx into a class and the markup and expressions just become code.
It is not interpreted at runtime.
PS. there was an MSDN Magazine article some time ago which dived into the compilation process, interesting to take a look at the compilation results with reflector.
Richard
2009-02-19 22:37:36
A:
There's no "context switch".
The way the ASP.NET works is the page is precompiled on the server side to executable code. Then, when a request comes, that code is executed and all server tags are replaced with the actual content they would yield in the response. After that the response is sent to the user.
Thus, anything you put as a <% %>
tag is executed on the server, before the HTML is served to the browser.
Franci Penov
2009-02-19 22:39:13