OdeToCode IC Logo

Code-behind for Me

Friday, June 3, 2005

In ASP.NET 2.0, I still prefer using code-behind over the single-file code model for web forms – but it is a tough choice.

In ASP.NET 1.x the choice was easy. Using a code-behind file was the only way to have intellisense when writing code, was the only way to catch syntax errors at build time, and was the only way to ‘pre-compile’ your code into an assembly before deployment.

All these reasons above go away in 2.0. In the single-file model your C# / VB.NET code exists inside a <script runat=”server”> tag, and within the same file as the ASPX / HTML markup for the web form. You’ll have intellisense, and the refactoring menu works, too. You can catch syntax errors by requesting a build, and still pre-compile the entire web application. In short, you won’t lose any productivity using a single-file model.

There are other advantages to the single-file model. There is only one file to check into source control. Only one file to diff when looking for changes between builds. Only one file to deploy, and only one file to copy when you want to sell company secrets to the highest bidder.

I like the simplicity of the single-file model. There are certainly fewer moving pieces. I just don’t like code intermingled with so much declarative markup – neither in ASP.NET or some of the Avalon samples I look at. I like to see a full class definition and not headless, floating method definitions. The mixture just isn't pretty.

I like to look at pretty code.

Perhaps this dislike could pass in time, but for now I’m putting code in a separate file.

Andy Friday, June 3, 2005
I'll take option 3, JSP w/Servlet's and or EJB's running on a server OS (Sun Solaris 10) that costs me 0 dollars to buy and 24X7 unlimited call support from Sun on the OS costs less than a personal copy of Windows XP.
<br>A web server that is light years easier to maintain and more stable than IIS ever hopes to be.(Apache and Tomcat)
<br>A stable and d@mn near bullet proof OS (although I will give server 2003 props for being way better than 2K it's still not a great server OS). MSFT has a long ways to go before I will trust my server code to them and because web development is so closely tied with server side stuff my web development still sees no reason to move to MSFT products.
<br>Besides JSP, Servlets, and EJB's are all stable technology where as .Net is still a beta and putting my enterprise code into something that is in beta is not my idea of good planning.
<br>This is actually on eof my biggest pet peeves with .Net if you read the fine print every &quot;release&quot; so far has been a beta release. When they finally stop churning and settle down I'll take a closer look but as long as it's in beta I won't bother.
<br>I would be willing to wager some money that we will not see a full non-beta release of .Net before Longhorn ships.
Bill Saturday, June 11, 2005
you rock Scotty
Comments are closed.