- Shopping Bag ( 0 items )
Teach yourself how to write high-performance Web applications with ASP.NET and Visual Basic .NET 2003—one step at a time. This practical, hands-on tutorial expertly guides you through the fundamental tools and technologies, including the common language runtime, Web Forms, XML Web services, and the Microsoft .NET Framework 1.1—including new ASP.NET mobile controls. Work at your own pace through the easy-to-follow lessons and hands-on exercises to learn essential techniques. And accelerate your productivity by ...
Ships from: Wauwatosa, WI
Usually ships in 1-2 business days
Ships from: Murphy, TX
Usually ships in 1-2 business days
Ships from: fallbrook, CA
Usually ships in 1-2 business days
Ships from: Chatham, NJ
Usually ships in 1-2 business days
Teach yourself how to write high-performance Web applications with ASP.NET and Visual Basic .NET 2003—one step at a time. This practical, hands-on tutorial expertly guides you through the fundamental tools and technologies, including the common language runtime, Web Forms, XML Web services, and the Microsoft .NET Framework 1.1—including new ASP.NET mobile controls. Work at your own pace through the easy-to-follow lessons and hands-on exercises to learn essential techniques. And accelerate your productivity by working with instructive code examples and best practices for ASP.NET Web development with Visual Basic .NET.
Discover how to:
Includes practice exercises and sample code on the Web
|Conventions Used in This Book|
|Pt. 1||Getting Started with ASP.NET|
|Ch. 1||Opening and Running an ASP.NET Web Application||3|
|Ch. 2||Creating an ASP.NET Web Application||33|
|Ch. 3||Understanding Programming Basics||49|
|Pt. 2||ASP.NET Infrastructure|
|Ch. 4||Managing State||87|
|Ch. 5||Configuring an ASP.NET Application||109|
|Ch. 6||Security in ASP.NET||127|
|Pt. 3||ASP.NET Web Forms|
|Ch. 7||Creating Web Forms||185|
|Ch. 8||Using Server Controls||225|
|Ch. 9||Accessing and Binding Data||275|
|Pt. 4||Beyond the Basics|
|Ch. 10||Creating Custom Server Controls||347|
|Ch. 11||Creating and Using Web Services||403|
|Ch. 12||Using Caching to Improve Performance||435|
|Ch. 13||Deploying as ASP.NET Application||459|
|Ch. 14||Tracing and Debugging ASP.NET Applications||477|
|App. A||Migrating from ASP to ASP.NET||501|
|App. B||ASP.NET Configuration Elements||513|
|App. C||Installing Visual Studio .NET 2003||555|
In this chapter, you will learn how to:
Now that you’ve learned about some of the features of Visual Studio .NET, the next step is to take advantage of them in your own applications. Conveniently enough, that’s precisely what you’re going to learn how to do in this chapter.
You’ll begin with an overview of the two major project types used for ASP.NET applications. Then you’ll look at the file types used in ASP.NET and the purpose of each. Next, you’ll learn how to create a new Web application, add a new Web Forms page, and add controls to the page and manipulate their properties. Finally, you’ll learn how to add event-handler code to the page, build the project, and test the page.
There are three basic types of ASP.NET applications, each with a distinct purpose. ASP.NET Web Applications are for a Web application that will provide its own HTML-based user interface. ASP.NET Web Services are for Web-based functionality that will be accessed programmatically. ASP.NET Mobile Web Applications, new in Visual Studio .NET 2003, are designed for creating Web applications targeted at Personal Digital Assistants (PDAs), cell phones, and other mobile devices. You can develop all of these application types with or without Visual Studio .NET, although the Visual Studio environment makes developing them significantly easier and faster. The following illustration shows the Visual Studio .NET New Project dialog box displaying the ASP.NET Web Application, ASP.NET Web Service, and ASP.NET Mobile Web Application project templates for Visual Basic .NET (some of the project templates shown might not appear in all editions of Visual Studio .NET).
ASP.NET applications, at their simplest, are much like classic ASP applications. The elements of a simple ASP.NET application are
For Visual Studio .NET users, the good news is that all of the preceding files are created for you when you create a new Web application project.
Web Forms are an important part of any ASP.NET Web application. Put simply, they are ASP.NET pages that use ASP.NET Server Controls. The Web Forms programming model makes it possible (and relatively easy) to develop Web-based applications in much the same way that today’s Microsoft Visual Basic programmers develop Microsoft Windows–based applications that have a GUI.
Web Forms in Visual Studio .NET allow you to create rich, interactive applications simply by dragging and dropping controls onto a page and then writing minimal code to handle user interaction, events, and so on. In addition, the Visual Studio .NET environment lets you work on your pages either visually—using the Web Forms Designer—or textually, using the powerful Visual Studio .NET source-code editor.
You can write code in your Web Forms in one of two ways: inline in the .aspx file (as is typical of a classic ASP page), or using a code-behind module. Although it’s possible to write your application with code in the actual .aspx file and still take advantage of compiled code and the other improvements of .NET, I recommend that you get in the habit of using code-behind modules. Visual Studio .NET defaults to using code-behind for UI-specific programming logic.
Code-behind is a new feature in ASP.NET that allows developers to truly separate the HTML and tag-based UI elements from the code that provides user interaction, validation, and so on. Code-behind modules offer developers a number of advantages:
All in all, it’s worthwhile to get into the habit of using code-behind. You’ll see examples of code-behind throughout the book.
Although no one would deny that Web applications created with ASP.NET (or even with classic ASP) can be very useful, one feature that has long been missing is an easy way to provide programmatic functionality over the Internet or an intranet without tying the client to a specific UI. This is where ASP.NET Web services come in.
A Web service, at its simplest, is a chunk of programming code that is accessible over the Web. Web services are based on the World Wide Web Consortium’s (W3C) SOAP specification. This allows computers on varying platforms, from Windows servers to UNIX workstations, to offer and consume programmatic services over the HTTP protocol.
ASP.NET makes it remarkably easy to implement Web services. In fact, all it takes is adding an appropriate declaration to any method you want to make available as a Web service. Visual Studio .NET makes it even easier by taking care of all the work necessary to make your Web service available to potential clients. Part IV will discuss Web services in greater detail.
Like standard ASP.NET Web applications, ASP.NET Mobile Web applications contain a number of standard elements:
As with the ASP.NET Web Application template, Visual Studio .NET creates all of the preceding files when you create a new ASP.NET Mobile Web application project. You’ll learn more about developing ASP.NET applications for mobile devices in Chapter 8.
You’ll see a number of new file types in your ASP.NET applications. To avoid any confusion, let’s take a minute to go over the ones you’ll see most often and discuss how they’re used.
In addition to the functionality available in a classic ASP Global.asa file, which was used for handling Application and/or Session start and end events and declaring Application- and/or Session-level variables, ASP.NET also allows you to import namespaces, link to assemblies, and perform other useful tasks. You’ll learn more about Global.asax in Chapter 7.
It’s certainly possible to create ASP.NET Web applications in Notepad or another text editor, but if you’re doing serious ASP.NET or component development, you’ll probably want to work within the Visual Studio .NET environment. The advantages of Visual Studio .NET over simple text editors include
That’s just a brief list. There’s much more to the tool than can be covered in a single chapter. So without further ado, let’s look at how to create projects and pages in the Visual Studio .NET environment.
One of the first things you’re going to want to do in order to work with ASP.NET in Visual Studio .NET is create a new project, or in Visual Studio .NET parlance, a Web application.
Create an ASP.NET Web application
Visual Studio .NET will create a new Web application along with physical and virtual directories for the project.
That’s it! You’ve created your first ASP.NET Web application. Note that this application is separate from the Chapter_02 project included with the practice file installation, which is contained in the aspnetsbs solution. Next we’ll look at how to add new pages.
In your new Web application, you’ll notice that Visual Studio .NET has already added a page named WebForm1.aspx to the project for you and opened it in the editor. Your Visual Studio .NET screen should look similar to the following illustration. However, since one page is rarely enough for most sites, let’s look at how to add a new page to your Web application.
Create a new ASP.NET page (Web Form)
As with creating a new project, there are several ways to add a new ASP.NET page (Web Form) to your application. The method you choose depends largely on how you like to work. Here are three ways to accomplish this task, although there are others:
Any of these methods will open the Add New Item dialog box, shown in the following illustration.
Visual Studio .NET creates the page, adds it to the project, and opens it in the Web Forms Designer, as shown in the following illustration.
Now that you’ve created a page for your new application, what can you do with it? Well, let’s begin by making it display a "Hello World!" greeting to the client. By default, Web Forms are opened in GridLayout mode. Since GridLayout relies on cascading style sheets (CSS), which are not supported in all browsers, you might want to change the page layout to FlowLayout mode.
Modify Web Form properties
When the page is selected, the word DOCUMENT should appear in the drop-down box at the top of the Properties window.
Until you add controls (or HTML elements), the page will display the following message in Design view.
Add controls to a Web Form
Add event handler code
This will open up the code-behind module for the Web Form and create an event handler procedure called Button1_Click.
Label1.Text = "Hello, " & TextBox1.Text & "!"
TextBox1.Visible = False
Button1.Visible = False
Because you modified the code-behind module for the Web Form, you need to build your project before you can browse the page. (You’ll learn more about code-behind in later chapters.) Building is the process of compiling all of the code modules in the project so they’ll be available to the pages and modules that call them. To build the project, from the Build menu, select Build Chapter_02 (or Build Solution, which will build all projects in the solution).
Once you’ve saved the Web Form page and its code-behind module and built the application, you can test the page.
Test your page
The result should look like the following illustration. (You can close the Output window if you want to see more of a page.)
The result should be similar to the following illustration. (Note that the Web toolbar shows the address of the page being browsed. You can enter this address in a browser window on your machine to view the page in a non-embedded browser window.)
|Create a new project in Visual Studio .NET||Click the New Project button, select the project language and template, and then provide the name and location for the new project.||(Image Unavailable)|
|Create a new Web Forms page||Click the Add New Item button (or click the arrow to the right and select Add Web Form). Provide a name for the new Web Form and click OK.||(Image Unavailable)|
|Save a file||Click the Save button, or select Save <filename> from the File menu.||(Image Unavailable)|