Search code examples
asp.netperformanceinline-code

ASP.NET Webform: inline code (<%= %> ) vs Server Control Performance?


Let's forget about state management, maintenance perspective, etc ... and focus on render performance only

Which of render method has better performance ? <%= ... %> or Server Control (or Html Server Control/ Custom Control/ UserControl) ?

e.g 1: Page1 vs

e.g 2: using <% %> with foreach to render a DataTable vs using DataGrid

In my opinion, <% %> will win not only in these 2 examples but also in most cases. As in ASP.NET MVC, we use inline code in Views to render HTML.

What's your opinion ?


Solution

  • It's a lot more difficult to manage <% %> code and it tends to be more brittle, IMO.

    It might be faster, but you lose maintainability. I have found if it's a data-heavy page, the price of the SQL Query is more expensive than the rendering speed of a GridView or a Repeater.

    (That and turning off ViewState.)