- •Contents
- •Introduction
- •Acknowledgments
- •The Goals of ASP.NET 2.0
- •Developer productivity
- •Administration and management
- •Performance and scalability
- •Device-specific code generation
- •Additional New Features of ASP.NET 2.0
- •New developer infrastructures
- •New compilation system
- •Additions to the page framework
- •New objects for accessing data
- •New server controls
- •A New IDE for Building ASP.NET 2.0 Pages
- •The Document Window
- •Views in the Document Window
- •The tag navigator
- •Page tabs
- •Code change status notifications
- •Error notifications and assistance
- •The Toolbox
- •The Solution Explorer
- •Lost Windows
- •Other Common Visual Studio Activities
- •Creating new projects
- •Making references to other objects
- •Using smart tags
- •Saving and importing Visual Studio settings
- •Application Location Options
- •Built-in Web server
- •Web site requiring FrontPage Extensions
- •The ASP.NET Page Structure Options
- •Inline coding
- •New code-behind model
- •New Page Directives
- •New attributes
- •New directives
- •New Page Events
- •Cross-Page Posting
- •New Application Folders
- •\Code folder
- •\Themes folder
- •\Resources folder
- •Compilation
- •The New Data Source Controls
- •The SqlDataSource and GridView Controls
- •Reading data
- •Applying paging in the GridView
- •Sorting rows in the GridView control
- •Defining bound columns in the GridView control
- •Enabling the editing of rows in the GridView control
- •Deleting data from the GridView
- •Dealing with other column types in the GridView
- •Selecting which fields to display in the DetailsView control
- •Using the GridView and DetailsView together
- •Updating, inserting, and deleting rows
- •XmlDataSource Control
- •ObjectDataSource Control
- •SiteMapDataSource Control
- •DataSetDataSource Control
- •Visual Studio 2005
- •Connection Strings
- •Site Maps
- •The PathSeparator property
- •The PathDirection property
- •The ParentLevelsDisplayed property
- •The ShowToolTips property
- •Examining the parts of the TreeView control
- •Binding the TreeView control to an XML file
- •Selecting multiple options in a TreeView
- •Specifying custom icons in the TreeView control
- •Specifying lines used to connect nodes
- •Working with the TreeView control programmatically
- •Applying different styles to the Menu control
- •Menu Events
- •Binding the Menu control to an XML file
- •SiteMap Data Provider
- •SiteMapViewType
- •StartingNodeType
- •SiteMap API
- •Why Do You Need Master Pages?
- •The Basics of Master Pages
- •Coding a Master Page
- •Coding a Content Page
- •Mixing page types and languages
- •Specifying which master page to use
- •Working with the page title
- •Working with controls and properties from the master page
- •Nesting Master Pages
- •Container-Specific Master Pages
- •Event Ordering
- •Caching with Master Pages
- •Using ASP.NET 2.0 Packaged Themes
- •Applying a theme to a single ASP.NET page
- •Applying a theme to an entire application
- •Applying a theme to all applications on a server
- •Removing themes from server controls
- •Removing themes from Web pages
- •Removing themes from applications
- •Creating Your Own Themes
- •Creating the proper folder structure
- •Creating a skin
- •Including CSS files in your themes
- •Having your themes include images
- •Defining Multiple Skin Options
- •Programmatically Working with Themes
- •Themes and Custom Controls
- •Authentication
- •Authorization
- •ASP.NET 2.0 Authentication
- •Setting up your Web site for membership
- •Adding users
- •Asking for credentials
- •Working with authenticated users
- •Showing the number of users online
- •Dealing with passwords
- •ASP.NET 2.0 Authorization
- •Using the LoginView server control
- •Setting up your Web site for role management
- •Adding and retrieving application roles
- •Deleting roles
- •Adding users to roles
- •Getting all the users of a particular role
- •Getting all the roles of a particular user
- •Removing users from roles
- •Checking users in roles
- •Using the Web Site Administration Tool
- •The Personalization Model
- •Adding a simple personalization property
- •Using personalization properties
- •Adding a group of personalization properties
- •Using grouped personalization properties
- •Defining types for personalization properties
- •Using custom types
- •Providing default values
- •Making personalization properties read-only
- •Anonymous Personalization
- •Enabling anonymous identification of the end user
- •Working with anonymous identification events
- •Anonymous options for personalization properties
- •Migrating Anonymous Users
- •Personalization Providers
- •Working with the Access personalization provider
- •Working with the SQL Server personalization provider
- •Using multiple providers
- •Building Dynamic and Modular Web Sites
- •Introducing the WebPartManager control
- •Working with zone layouts
- •Understanding the WebPartZone control
- •Explaining the WebPartPageMenu control
- •Modifying zones
- •Caching in ASP.NET 1.0/1.1
- •Output caching
- •Partial page caching
- •Data caching using the Cache object
- •Cache dependencies
- •ASP.NET 2.0 unseals the CacheDependency class
- •Enabling databases for SQL Server cache invalidation
- •Enabling tables for SQL Server cache invalidation
- •Looking at SQL Server
- •Looking at the tables that are enabled
- •Disabling a table for SQL Server cache invalidation
- •Disabling a database for SQL Server cache invalidation
- •Configuring your ASP.NET Application
- •Adding more than one table to a page
- •Attaching SQL Server cache dependencies to the Request object
- •Attaching SQL Server cache dependencies to the Cache object
- •Customizing the side navigation
- •Examining the AllowReturn attribute
- •Working with the StepType attribute
- •Adding a header to the Wizard control
- •Utilizing Wizard control events
- •Working with images from disk
- •Resizing images
- •Displaying images from streams
- •The MMC ASP.NET Snap-In
- •General
- •Custom Errors
- •Authorization
- •Authentication
- •Application
- •State Management
- •Advanced
- •ASP.NET Web Site Administration Tool
- •Home
- •Security
- •Profile
- •Application
- •Provider
- •Managing the Site Counter System
- •Generics
- •Iterators
- •Anonymous Methods
- •Operator Overloading
- •Visual Basic XML Documentation
- •New Visual Basic Keywords
- •Continue
- •Using
- •Global
- •Index
Chapter 15
Listing 15-16: Visual Basic code with comments for XML documentation
Imports Microsoft.VisualBasic
‘’’ <summary>My Calculator Class</summary> Public Class Class1
‘’’ <summary>This Add method returns the value of two numbers ‘’’ added together</summary>
‘’’ <param name=”a”>First number of the collection of numbers to
‘’’ be added</param>
‘’’ <param name=”b”>Second number of the collection of numbers to ‘’’ be added</param>
Public Function Add(ByVal a As Integer, ByVal b As Integer) Return (a + b)
End Function
End Class
The Visual Basic 8.0 compiler now includes a new /doc command that is similar to the way C# works with XML documentation. Compiling your VB code using the /doc command causes the compiler to produce the XML documentation with the compilation.
New Visual Basic Keywords
Visual Basic 8.0 introduces a couple of new keywords that can be utilized in your ASP.NET 2.0 applications. The keywords were brought to the language to make it easier to perform some common tasks, such as working in loops or destroying resources as early as possible. Look at a couple of the new additions to the Visual Basic language.
Continue
The Continue statement is an outstanding new addition to the Visual Basic language that was brought on board to enable you to work through loops more logically in some specific situations. When working in a loop, it is sometimes beneficial to stop the conditional flow and move onto the next item in the collection if the item being examined simply doesn’t fit your criteria. This logic can now be implemented better because of the new Continue statement. Listing 15-17 shows an example of the use of the Continue statement.
Listing 15-17: Using the Continue statement
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Dim myString As String
Dim count As Integer = 0
myString = “The St. Louis Rams will go to the Superbowl this year.”
For i As Integer = 0 To (myString.Length() - 1) If (myString(i).Equals(“ “c)) Then Continue For
count += 1
426
Visual Basic 8.0 and C# 2.0 Language Enhancements
Next
Label1.Text = “There are “ & count.ToString() & _ “ characters used (minus spaces).”
End Sub
This little example takes a String and counts each character in the complete string that is not a space. If a space is encountered, the Continue statement finds this in the check and immediately stops execution of the loop for that particular item in the collection. It then hands over the execution of the loop to the next item in the collection. In this example, you could easily check for the characters with a nested If statement, but using multiple nested If statements can get confusing sometimes. The use of the Continue statement makes the logic contained within the For loop very evident and clean.
The Continue statement is not only meant to be used within a For loop, but you can also use this new keyword with other language features that loop through a collection of items — such as the Do and While statements. The following example shows how to use the Continue statement with the four available options:
For [statement]
...
If [statement] Then Continue For
...
Next
For Each [statement]
...
If [statement] Then Continue For
...
Next
Do While [statement]
...
If [statement] Then Continue Do
...
Loop
While [statement]
...
If [statement] Then Continue While
...
End While
As you can see, you have many ways to use this new keyword to make your code easier to read and manage.
427
Chapter 15
Using
Although the using keyword in C# is quite prevalent (one use being to import namespaces into a class), the new Visual Basic Using keyword should not be confused with this C# version. It is similar to the C# using statement that defines the scope of an object.
You use the Using keyword in Visual Basic to ensure that expensive resources get destroyed as soon as possible instead of allowing them to sit in memory until the method is executed. You can now destroy expensive resources, such as connection objects and COM wrappers, immediately when you have finished using them instead of waiting for the garbage collector to come by and make its rounds. An example of working with the Using keyword is illustrated in Listing 15-18.
Listing 15-18: Working with the Using keyword
Using myConn As New SqlConnection
‘ Work with the SqlConnection object
End Using
In Listing 15-18, you can see that instead of using the Dim keyword to create a new instance of the SqlConnection object, the Using keyword is used in its place. If you utilize the Using keyword, you must close the Using statement with an End Using statement. The End Using statement is located at the point where the SqlConnection object is destroyed from memory.
My
My, oh my, what a new keyword! The My keyword is a novel concept to quickly give you access to your application, the computer, or the network in which the application resides. The My keyword has been referred to as a way of speed-dialing common but complicated resources that you need access to. Using the My keyword, you can quickly get access to a wide variety of items such as user details or specific settings of the requestor’s browser.
If you type the My keyword into your application, you will notice that IntelliSense provides you with three items to work with: Application, Computer, and User. Although this new keyword works best in the Windows Forms environment, there are still things you can use in the Web Forms world.
If you want to get at the identity of a user, for example, you can use the following construct:
Label1.Text = My.User.Identity.Name.ToString()
Another example is checking whether the browser making the request to the application is a mobile device. For this, you would use the following construction:
Label1.Text = My.Application.Request.Browser.IsMobileDevice.ToString()
You can get to the information stored in files, system settings, and more in a number of quick ways. The best way to explore the My namespace is to look through IntelliSense and see what is available.
428
Visual Basic 8.0 and C# 2.0 Language Enhancements
Global
The Global keyword was added as a top-root namespace to avoid any namespace conflicts that might arise from similarly named namespaces. Here is an example of how you can use the Global keyword:
Global.System.String
Summar y
This short chapter looked at some of the changes to the C# and Visual Basic languages in their latest releases. When a new version of the .NET Framework comes along, everything associated with it is refreshed at the same time. With .NET Framework 2.0, not only do you get a new version of ASP.NET, but new versions of all the Microsoft .NET-compliant languages, Windows Forms, and more.
The new features of C# and VB illustrated in this chapter can be directly used in the ASP.NET 2.0 applications you are building — giving you applications that contain cleaner and better-performing code.
429
