Controls, Partial Classes, and Smart Tags
To add controls to a page you can drag and drop them from the Toolbox (Design mode) or you can manually edit the HTML in source mode. The Design and Source tabs along the bottom of the page designer are used to jump back and forth between the two modes. The ASP.NET 2.0 Toolbox has new controls since ASP.NET 1.0/1.1 and existing controls have been better categorized (see Figure 4
|Figure 4: The Toolbox contains all the controls categorized by function.||
|Figure 5: Use the "Add New Item" dialog box to add items to your web project.||
|The code-behind model uses a feature in the .NET Framework 2.0 called partial classes. Partial classes are classes defined in two or more source files and combined at compilation time to create a single class.|
To add items to the web site, right-click the web site name and select "Add New Item" from the shortcut menu. The Add New Item dialog box (see Figure 5
) shows the types of things you can add to your web site. Note the "Place code in separate file" check box on the Add New Item dialog box. It represents the code-behind model implemented in ASP.NET 2.0.
The code-behind model uses a feature in the .NET Framework 2.0 called partial classes
. Partial classes are classes defined in two or more source files and combined at compilation time to create a single class. Prior to ASP.NET 2.0, control declarations were stored in the Form Designer-generated section of code-behind files. ASP.NET 2.0 stores the control declarations in a separate file from the file where you create your own code-behind classes. To make sure that the control declarations do not get out of sync, the declarations for the web controls are not generated by Visual Studio 2005 at design time but are created by the ASP.NET runtime during compilation.
Throughout this article I'll make references to smart tags, which you can think of as a list of the most commonly used properties or tasks for a control. You access the smart tags for a control by clicking the glyph (small black triangle) in the upper right-hand corner of the control.
Table 1 illustrates some special system-defined folders.
Table 1. System-Defined Folders: ASP.NET uses these system-defined folders to hold specific portions of applications.
Reusable, non-page classes that are dynamically compiled at run time and made available to the application as a single assembly. Examples include utility classes and business objects.
Designed to contain file-based databases used by the application including SQL Server Express (.mdf) and Access (.mdb) databases.
Stores Web service references used by the application.
Stores browser definition files used by ASP.NET to identify individual browsers and determine their capabilities.
Stores all of the specific themes and skins for the application.
You store all of your non-page classes such as utility classes, business objects, or any other classes you may have created in the App_Code
folder. To add an App_Code
folder to your project, right-click the project name and select "Add ASP.NET Folder" and then select App_Code
. ASP.NET monitors the folder, so whenever you change a class in the App_Code
folder, ASP.NET will dynamically recompile the class and automatically make it available to the entire site. You can even place classes coded in different languages in subdirectories under the App_Code
directory. Each subdirectory needs to be registered with a particular language in web.config
folder makes database integration easy. The App_Data
folder holds file-based data stores including SQL Server Express 2005 database files (.mdf
files), Access database files (.mdb
files), Excel worksheets, XML files, and so on. The primary advantage of using App_Data
is that files placed there are not downloadable if a request is made for the file over the wire.
|Figure 6: You can elect to set the current page or a specific page as the start page in the Start Options in the project's Properties dialog.|
ASP.NET's compilation model offers a number of benefits including the ability to run the current form each time you run the site. A project's Start Options, available on the project's Property Pages dialog box, specifies, among other options, the ability to launch the current page or a specific page each time the site is launched (see Figure 6
). See the article by Rick Strahl referred to in the "Reading Suggestions
The ASP.NET Web Site Administration Tool page (see Figure 7
) makes it fairly easy to administer your web site. You can launch it by selecting the ASP.NET Administration icon on the top of the Solution Explorer (see Figure 8
). You can manage all aspects of your site with this tool including security, application settings, and providers. The security features include being able to add and delete users, assign folder permissions, add and delete user roles, and assign users to specific roles. The application settings include being able to add and remove application variables, configure email settings, take the site offline, configure the debugging and tracing options, and specify which page to use as the default error page.
|Figure 7: The ASP.NET Web Site Administration Tool provides site configuration features.||
|Figure 8: You access the Web Site Administration tool from the Solution Explorer.||