1. Home
  2. Computing & Technology
  3. Visual Basic

Learn ASP.NET 2.0 - VWD in more depth
Code-Beside - A Tweak to Code-Behind

By Dan Mabbutt, About.com

Apr 6 2008

In Part 1, I introduced the concept of code-behind. Code-behind refers to code for your ASP.NET page that is contained in a separate class file that's executed on the server. In ASP.NET 2.0, this allows the web design (the HTML code in the .aspx file) to be completely separate from the programming (the VB.NET code in the .vb file).

To make sure that the concept is clear, let's contrast both techniques. Start a new website in VWD and then select New File... and then Web Form from the templates window. But before clicking the Add button for a new web form, uncheck the Place code in separate file box.

This will give you one page that has code-behind logic and one page that has single file (also called inline) logic. This illustration shows the result (it's a big graphic ... you may have to scroll and/or enlarge it):

--------
Click Here to display the illustration
Click the Back button on your browser to return
--------

Note that ASP.NET 2.0 (the version we're using) relies on Partial classes. This means that the resulting class file is the merged result of the .aspx and the .vb file. One advantage of partial classes is that the generated code sections that used to be in special marked sections aren't there now. This makes is much less likely that a mistake will be made by changing them and it also makes for less complicated files where you write your own code. Finally, it's the way Microsoft implements a lot of new enhancements such as Master Pages.

Explore Visual Basic
By Category
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic
  4. Learn VB.NET
  5. Learn ASP.NET
  6. Learn ASP.NET 2.0 - VWD in more depth

©2009 About.com, a part of The New York Times Company.

All rights reserved.