But what does Partial mean? A new feature in .NET 2.0, partial classes allow
a class to be spread over multiple files. ASP.NET 2.0 uses this feature to make
programmers lives easier. We write one part of the class in the code-behind file,
and ASP.NET generates the other part of the class for us, adding the object de-
clarations for all the user interface elements.
Take a look at the Click subroutine, though which we access the messageLabel
object without defining it anywhere in the code:
Visual Basic File: HelloCodeBehind.vb (excerpt)
Sub Click(s As Object, e As EventArgs)
messageLabel.Text = "Hello World"
End Sub
Thats pretty handy! However, dont be fooled into thinking that you can use
objects that havent been declaredthe messageLabel object has been declared
in another partial class file that the ASP.NET runtime generates for us. The file
contains declarations for all the controls referenced in HelloCodeBehind.aspx.
As I hope you can see, code-behind files are easy to work with, and they can make
managing and using our pages much more straightforward than keeping your
code in code declaration blocks. Youll find yourself using code-behind files in
most of the real-world projects that you build, but for simplicitys sake, well stick
with code declaration blocks for one more chapter.
Summary
Phew! Weve covered quite a few concepts over the course of this chapter. Dont
worrywith a little practice, these concepts will become second nature to you.
I hope you leave this chapter with a basic understanding of programming concepts
as they relate to the ASP.NET web developer.
The next chapter will begin to put all the concepts that weve covered so far into
practice. Well begin by working with HTML Controls, Web Forms, and Web
Controls, before launching into our first hands-on project!
92
Chapter 3: VB and C# Programming Basics

Get Build Your Own ASP.NET 2.0 Web Site Using C# & VB, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.