Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Build Your Own ASP.NET 2.0 Web Site Using CSharp And VB (2006) [eng]-1.pdf
Скачиваний:
142
Добавлен:
16.08.2013
Размер:
15.69 Mб
Скачать

Summary

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 declarations 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

That’s pretty handy! However, don’t be fooled into thinking that you can use objects that haven’t been declared—the 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. You’ll find yourself using code-behind files in most of the real-world projects that you build, but for simplicity’s sake, we’ll stick with code declaration blocks for one more chapter.

Summary

Phew! We’ve covered quite a few concepts over the course of this chapter. Don’t worry—with 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 we’ve covered so far into practice. We’ll begin by working with HTML Controls, Web Forms, and Web Controls, before launching into our first hands-on project!

91

92