- •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 3
\Themes folder
Themes are a new way of providing a common look and feel to your site across every page. You implement a theme by using .skin file, CSS files, and images used by the server controls of your site. All these elements can make a Theme, which is then stored in the \Themes folder of your solution. By storing these elements within the \Themes folder, you ensure that all the pages within the solution can take advantage of the theme and easily apply its elements to the controls and markup of the page. Themes are discussed in great detail in Chapter 7 of this book.
\Resources folder
Resource files are string tables that can serve as data dictionaries for your applications when these applications require changes to content based on things such as changes in culture. You can add Assembly Resource Files (.resx) to this folder, and they are dynamically compiled and made part of the solution for use by your .aspx pages. When using ASP.NET 1.0/1.1, you were required to use the resgen.exe tool and to compile your resource files to a DLL or EXE for use within your solution. Now it is considerably easier to deal with resource files in ASP.NET 2.0.
In addition to strings, you can also add images and other files to your resource files. For an example of how to use resource files to create a multilingual ASP.NET 2.0 application, first create the \Resources folder in your application. For this example, create two resource files in this folder — Resource.resx and Resource.fi-FI.resx. The first file, Resource.resx is the default language file using American English. The second file is for the same text, but in the Finnish language. Hence, this file uses fi-FI in its name. When someone with a browser culture of fi-FI invokes the page, he sees the information that comes from this file (Resource.fi-FI.resx). Everyone else who comes to the site gets the information that comes from the other file (Resource.resx).
Notice (as shown in Figure 3-11) that you can actually do a lot with .resx files. The idea is to create a table of the items that need to be localized (such as text, images, and files). For this example, you can stick to text.
The Resource.resx file should have the following structure:
Name |
Value |
Answer |
Hello there |
PageTitle |
Sample Page |
Question |
What is your name? |
For the Resource.fi-FI.resx file, you should use the following structure:
Name |
Value |
Answer |
Hei |
PageTitle |
Näytesivu |
Question |
Mikä sinun nimi on? |
66
Application and Page Frameworks
Figure 3-11
To use these files, create a simple .aspx page using the code from Listing 3-16.
Listing 3-16: A simple ASP.NET page that uses resource files
VB
<%@ Page Language=”VB” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN” “http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>
<script runat=”server”>
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Page.Title = Resources.Resource.PageTitle
End Sub
Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Label1.Text = Resources.Resource.Answer & “ “ & Textbox1.Text
End Sub </script>
(continued)
67
Chapter 3
Listing 3-16: (continued)
<html xmlns=”http://www.w3.org/1999/xhtml” > <head id=”Head1” runat=”server”>
<title></title>
</head>
<body>
<form id=”Form1” runat=”server”>
<p><%= Resources.Resource.Question %></p><br />
<asp:textbox id=”Textbox1” runat=”server”></asp:textbox><br /> <asp:button id=”Button1” runat=”server” text=”Submit” onclick=”Button1_Click” />
<p><asp:label id=”Label1” runat=”server”></asp:label></p> </form>
</body>
</html>
C#
<%@ Page Language=”C#” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.1//EN” “http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd”>
<script runat=”server”>
void Page_Load(object sender, System.EventArgs e)
{
Page.Title = Resources.Resource.PageTitle;
}
void Button1_Click(object sender, System.EventArgs e)
{
Label1.Text = Resources.Resource.Answer + “ “ + Textbox1.Text;
}
</script>
When this is run, you get the appropriate text based upon the culture setting in your browser. If this setting is not fi-FI, you get the American English text. The page output is shown in Figure 3-12.
Figure 3-12
68
