Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does adding server side code in markup page (aspx) affect performance?

At my previous job, our team architect was strongly against including any server side code in the markup, even simple ID's, so this code would not be allowed to get checked in:

<script>
    var el = document.getElementByID('<% SomeElement.ClientID %>')
</script>

instead you had to inject it into javascript via Page.ClientScript.Register...

His reason was that asp.net has to recompile a page every time if it has those server code includes.

That didn't sound right for me but I couldn't find any proof of either.

Any ideas? Does that change performance or not? I know that server side code in markup is not good because of difficulties in debugging and readability and the whole idea of separatin gcode form markup, but I am only interested in performance differences.

Thanks!

like image 542
Andrey Avatar asked Apr 15 '26 01:04

Andrey


1 Answers

Your architect is wrong.

ASP.NET compiles a page once, regardless of whether or not it contains any C# code. It will recompile the page only if it detects that the ASPX file was changed since last compilation.

like image 191
Fyodor Soikin Avatar answered Apr 17 '26 14:04

Fyodor Soikin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!