- •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 10
Figure 10-16
Modifying zones
One aspect of the Portal Framework that merits special attention is the capability to modify zones on the page. These zones allow for a high degree of modification — not only in the look and feel of the items placed in the zone, but also in terms of the behaviors of zones and the items contained in the zones as well. Following are some examples of what you can do to modify zones.
Turning off the capability for modifications in a zone
As you have seen, giving end users the capability to move Web Parts around the page is quite easy, whether within a zone or among entirely different zones. When working with the Portal Framework and multiple zones on a page, you do not always want to allow the end user to freely change the items that appear in every zone. You want the items placed in some zones to be left alone. Listing 10-7 shows an example of this.
Listing 10-7: Turning off the zone modfication capability
<asp:WebPartZone ID=”WebPartZone1” Runat=”server” LayoutOrientation=”Horizontal” AllowLayoutChange=”false”>
<ZoneTemplate>
310
Portal Frameworks and Web Parts
<asp:Label ID=”Label1” Runat=”server” Text=”Label” Title=”Welcome to my web page!”>
Welcome to the page! </asp:Label>
</ZoneTemplate>
</asp:WebPartZone>
In this example, the first Web Part Zone, WebPartZone1, uses the AllowLayoutChange attribute with a value of False, which turns off the end user’s capability to modify this particular Web Part Zone. When you run this page and go to the design mode, notice that you cannot drag and drop any of the Web Parts from the other zones into WebPartZone1. Neither can you grab hold of the Label Web Part contained in WebPartZone1. No capability exists to minimize and close the Web Parts contained in this zone. It allows absolutely no modifications.
Here is another interesting change you may notice when you are working in the page catalog mode with the AllowLayoutChange attribute set to False. After you select items to add to the page through the page catalog, WebPartZone1 does not appear in the drop-down list of places where you can publish the Web Parts (see Figure 10-17). From this figure, you can see that only WebPartZone2 and WebPartZone3 appear and allow modifications.
Figure 10-17
311
Chapter 10
Adding controls through other means
Earlier in this chapter, you examined how to use the <asp:PageCatalogPart> control to restore controls to a page after they had been deleted. Although the <asp:PageCatalogPart> is ideal for this, you might also want to allow the end user to add Web Parts that are not on the page by default. You may want to enable the end user to add more than one of any particular Web Part to a page. For these situations, you work with the <asp:DeclarativeCatalogPart> control.
Listing 10-8 shows an example of using this type of catalog system in place of the
<asp:PageCatalogPart> control.
Listing 10-8: Using the DeclarativeCatalogPart control
<asp:CatalogZone ID=”Catalogzone1” Runat=”server”> <ZoneTemplate>
<asp:DeclarativeCatalogPart ID=”Declarativecatalogpart1” Runat=”server”> <WebPartsTemplate>
<uc1:CompanyContactInfo ID=”CompanyContact” Runat=”Server” /> <uc1:PhotoAlbum ID=”PhotoAlbum” Runat=”Server” /> <uc1:Customers ID=”Customers” Runat=”Server” /> <uc1:Locations ID=”Locations” Runat=”Server” />
</WebPartsTemplate>
</asp:DeclarativeCatalogPart>
</ZoneTemplate>
</asp:CatalogZone>
Instead of using the <asp:PageCatalogPart> control, this catalog uses the <asp:Declarative CatalogPart> control. This templated control needs a <WebPartsTemplate> section where you place all the available controls. The controls appear in the check box list in the same order in which you declare them in the <WebPartsTemplate> section. Figure 10-18 shows how the catalog will look in the Design view in Visual Studio 2005.
Figure 10-18
This catalog lets you select items from the list of Web Parts and assign the location of the zone in which they will be placed. Once placed, notice that the option to add these Web Parts has not disappeared as it did with the earlier PageCatalogPart control. In fact, you can add as many of these items to the page as you deem necessary — even if it is to the same zone within the Portal Framework.
Even using the DeclarativeCatalogPart control is not always 100% ideal. When the end user closes one of the Web Parts that initially appears on the page, he does not see that control listed in the DeclarativeCatalogPart control’s list of elements. In fact, the end user cannot re-add these deleted items. Using both the
312
Portal Frameworks and Web Parts
PageCatalogPart control and the DeclarativeCatalogPart control simultaneously is the best solution. The great thing about this framework is that it allows you to do that. The Portal Framework melds both controls into a cohesive control that not only enables you to add controls that are not on the page by default, but it also lets you add previously deleted default controls. Listing 10-9 shows an example of this.
Listing 10-9: Combining both catalog types
<asp:CatalogZone ID=”Catalogzone1” Runat=”server”> <ZoneTemplate>
<asp:PageCatalogPart ID=”Pagecatalogpart1” Runat=”server” /> <asp:DeclarativeCatalogPart ID=”Declarativecatalogpart1” Runat=”server”>
<WebPartsTemplate>
<uc1:CompanyContactInfo ID=”CompanyContact” Runat=”Server” /> <uc1:PhotoAlbum ID=”PhotoAlbum” Runat=”Server” /> <uc1:Customers ID=”Customers” Runat=”Server” /> <uc1:Locations ID=”Locations” Runat=”Server” />
</WebPartsTemplate>
</asp:DeclarativeCatalogPart>
</ZoneTemplate>
</asp:CatalogZone>
In this example, both the PageCatalogPart control and the DeclarativeCatalogPart control are contained with the <ZoneTemplate> section. When this page is run, you see the results shown in Figure 10-19.
Figure 10-19
313
Chapter 10
You can see that each catalog is defined within the Catalog Zone. Figure 10-19 shows the PageCatalogPart control’s collection of Web Parts (defined as Page Catalog), while a link to the Declarative Catalog is provided for that particular list of items. Note that the order in which the catalogs appear in the <ZoneTemplate> section is the order in which the links appear in the Catalog Zone.
Web Part verbs
Web Part verbs declare the actions of the items (such as Minimize and Close) that appear in the title. These verbs are basically links that initiate an action for a particular Web Part. The available list of Web Part verbs includes
<CloseVerb>
<ConnectVerb>
<EditVerb>
<ExportVerb>
<HelpVerb>
<MinimizeVerb>
<RestoreVerb>
The <asp:WebPartZone> control allows you to control these verbs by nesting the appropriate verb elements within the <asp:WebPartZone> element itself. After these are in place, you can manipulate how these items appear in all the Web Parts that appear in the chosen Web Part Zone.
For example, look at graying out the default Close link included with a Web Part. This is illustrated in Listing 10-10.
Listing 10-10: Graying out the Close link in a Web Part
<asp:WebPartZone ID=”WebPartZone3” Runat=”server”> <CloseVerb Enabled=”False” /> <ZoneTemplate>
<asp:Calendar ID=”Calendar1” Runat=”server”> </asp:Calendar>
</ZoneTemplate>
</asp:WebPartZone>
In this example, you can see that you simply need to set the Enabled attribute of the <CloseVerb> element to False in order to gray out the Close link in any of the generated Web Parts included in this Web Part Zone. If you construct the Web Part Zone in this manner, you achieve the results shown in Figure 10-20.
314
Portal Frameworks and Web Parts
Figure 10-20
If you don’t want to gray out the Close link (or any other verb link contained within the Web Part), you must instead use the Visible attribute of the appropriate verb (see Listing 10-11).
Listing 10-11: Removing the Close link in a Web Part
<asp:WebPartZone ID=”WebPartZone3” Runat=”server”> <CloseVerb Visible=”False” /> <ZoneTemplate>
<asp:Calendar ID=”Calendar1” Runat=”server”> </asp:Calendar>
</ZoneTemplate>
</asp:WebPartZone>
Using the Visible attribute produces the screen shown in Figure 10-21.
315
Chapter 10
Figure 10-21
Verb elements provide another exciting feature: They give you the capability to use images for the items rather than default text. Using images instead of text makes the Web Parts appear more like the overall Windows environment. For instance, you can change the contents of WebPartZone3 again so that it now uses images instead of text for the Close and Minimize links. This is illustrated in Listing 10-12.
Listing 10-12: Using images for the Web Part verbs
<asp:WebPartZone ID=”WebPartZone3” Runat=”server”> <CloseVerb ImageUrl=”Images/CloseVerb.gif” />
<MinimizeVerb ImageUrl=”Images/MinimizeVerb.gif” /> <ZoneTemplate>
<asp:Calendar ID=”Calendar1” Runat=”server”> </asp:Calendar>
</ZoneTemplate>
</asp:WebPartZone>
To point to an image for the verb, use the ImageUrl attribute. This produces something similar to Figure 10-22, depending on the images you use.
316
Portal Frameworks and Web Parts
Figure 10-22
This chapter thus far has concentrated on creating completely customizable portal applications in a declarative manner using the capabilities provided by the ASP.NET Portal Framework. As with most aspects of ASP.NET, however, not only can you work with appearance and functionality in a declarative fashion, but you can also create the same constructs through server-side code.
Working with Classes in the Por tal Framework
The Portal Framework provides three main classes for dealing with the underlying framework presented in this chapter: WebPartManager, WebPartZone, and WebPart.
The WebPartManager class allows you to perform multiple operations in your server-side code. The following table shows a partial listing of some of the properties that this class provides.
317
Chapter 10
WebPartManager Class Properties |
Description |
|
|
Connections |
Provides a collection of all the connections between Web |
|
Parts contained on the page. |
DisplayMode |
Allows you to change the page’s display mode. |
|
Possible choices include CatalogDisplayMode, |
|
ConnectDisplayMode, DesignDisplayMode, |
|
EditDisplayMode, and NormalDisplayMode. |
EnableCatalogDisplayMode |
Takes a Boolean value and either enables or disables the |
|
capability to turn on the page in the catalog mode. |
EnableConnectDisplayMode |
Takes a Boolean value and either enables or disables the |
|
capability to turn on the page in the connect mode. |
EnableDesignDisplayMode |
Takes a Boolean value and either enables or disables the |
|
capability to turn on the page in the design mode. |
EnableEditDisplayMode |
Takes a Boolean value and either enables or disables the |
|
capability to turn on the page in the display mode. |
SelectedWebPart |
Allows you to perform multiple operations on the |
|
selected Web Part. |
WebParts |
Provides a collection of all the Web Parts contained on |
|
the page. |
Zones |
Provides a collection of all the Web Part Zones contained |
|
on the page. |
|
|
Beyond the properties of the WebPartManager class, you also have an extensive list of available methods at your disposal. The following table outlines some of the available methods of the
WebPartManager class.
WebPartManager Class Methods |
Description |
|
|
AddWebPart |
Allows you to dynamically add new Web Parts to a par- |
|
ticular zone on the page. |
ConnectWebParts |
Allows you to connect two Web Parts together via a com- |
|
mon property or value. |
DeleteWebPart |
Allows you to dynamically delete new Web Parts from a |
|
particular zone on the page. |
DisconnectWebParts |
Allows you to delete a connection between two Web |
|
Parts. |
MoveWebPart |
Allows you to move a Web Part from one zone to |
|
another, or allows you to change the index order in |
|
which Web Parts appear in a particular zone. |
|
|
318
Portal Frameworks and Web Parts
Whereas the WebPartManager class allows you to manipulate the location, addition, and deletion of Web Parts that appear in the page as a whole, the WebPartZone class allows you to modify a single Web Part Zone on the page. The following table provides a list of some properties available to the
WebPartZone class.
WebPartZone Class Properties |
Description |
|
|
AllowLayoutChange |
Takes a Boolean value and either enables or disables the |
|
Web Part Zone’s capability to accept or allow any |
|
changes in the Web Parts it contains. |
BackColor, BackImageUrl, |
Enable you to modify the Web Part Zone’s general |
BorderColor, BorderStyle, |
appearance. |
BorderWidth |
|
CloseVerb |
References the Close verb for a particular Web Part Zone |
|
from which you can then manipulate the verb’s |
|
Description, Enabled, ImageUrl, Text, and Visible |
|
properties. |
ConnectVerb |
References a Web Part Zone’s Connect verb from which |
|
you can then manipulate the verb’s Description, |
|
Enabled, ImageUrl, Text, and Visible properties. |
DragHighlightColor |
Takes a System.Color value that sets the color of the |
|
Web Part Zone’s border if focused when the moving |
|
of Web Parts is in operation. This also changes the color |
|
of the line that appears in the Web Part Zone specifying |
|
where to drop the Web Part. |
EditVerb |
References a Web Part Zone’s Edit verb from which you |
|
can then manipulate the verb’s Description, Enabled, |
|
ImageUrl, Text, and Visible properties. |
EmptyZoneText |
Sets the text that is shown in the zone if a Web Part is not |
|
set in the zone. |
HeaderAlignment |
Allows you to align the Web Part Zone header. |
HeaderText |
Sets header text. |
Height |
Sets the height of the Web Part Zone. |
HelpVerb |
References a Web Part Zone’s Help verb from which you |
|
can then manipulate the verb’s Description, Enabled, |
|
ImageUrl, Text, and Visible properties. |
MenuImageUrl, MenuLabelStyle, |
Enable you to modify the drop-down menu that appears |
MenuLabelText, MenuText |
when end users edit a Web Part. These properties let you |
|
apply an image, alter the text, or change the style of the |
|
menu. |
MinimizeVerb |
References a Web Part Zone’s Minimize verb from which |
|
you can then manipulate the verb’s Description, |
|
Enabled, ImageUrl, Text, and Visible properties. |
|
|
|
Table continued on following page |
319
Chapter 10
WebPartZone Class Properties |
Description |
|
|
Orientation |
Enables you to change the Web Part Zone’s orientation |
|
from horizontal to vertical or vice versa. |
RestoreVerb |
References a Web Part Zone’s Restore verb, from which |
|
you can then manipulate the verb’s Description, |
|
Enabled, ImageUrl, Text, and Visible properties. |
VerbButtonType |
Enables you to change the button style. Choices include |
|
ButtonType.Button, ButtonType.Image, or |
|
ButtonType.Link. |
WebParts |
Provides a collection of all the Web Parts contained |
|
within the zone. |
Width |
Sets the width of the Web Part Zone. |
|
|
You have a plethora of options to manipulate the look and feel of the Web Part Zone and the items contained therein.
The final class is the WebPart class. This class enables you to manipulate specific Web Parts located on the page. The following table details some of the available properties of the WebPart class.
WebPart Class Properties |
Description |
|
|
AllowClose |
Takes a Boolean value that specifies whether the Web |
|
Part can be closed and removed from the page. |
AllowEdit |
Takes a Boolean value that specifies whether the end |
|
user can edit the Web Part. |
AllowHide |
Takes a Boolean value that specifies whether the end |
|
user can hide the Web Part within the Web Part Zone. If |
|
the control is hidden, it is still in the zone, but invisible. |
AllowMinimize |
Takes a Boolean value that specifies whether the end |
|
user can collapse the Web Part. |
AllowPaginate |
Takes a Boolean value that specifies whether the Web |
|
Part can be paginated using the ASP.NET Pager server |
|
control. |
AllowZoneChange |
Takes a Boolean value that specifies whether the end |
|
user can move the Web Part from one zone to another. |
BackColor, BackImageUrl, |
Enable you to modify the Web Part’s general appearance. |
BorderColor, BorderStyle, |
|
BorderWidth |
|
Caption |
Sets an item of text directly in the title bar next to the |
|
Web Part’s title. This property allows you to differentiate |
|
among multiple Web Parts that have the same title. |
|
|
320
|
|
Portal Frameworks and Web Parts |
|
|
|
|
WebPart Class Properties |
Description |
|
|
|
|
ChromeState |
Specifies whether the Web Part chrome is in a normal |
|
|
state or is minimized. |
|
ChromeType |
Specifies the chrome type that the Web Part uses. Avail- |
|
|
able options include BorderOnly, Default, None, |
|
|
TitleAndBorder, and TitleOnly. |
|
Direction |
Specifies the direction of the text or items placed within |
|
|
the Web Part. Available options include LeftToRight, |
|
|
NotSet, and RightToLeft. This property is ideal for |
|
|
dealing with Web Parts that contain Asian text that is |
|
|
read from right to left. |
|
HelpMode |
Specifies how the help items display when the end user |
|
|
clicks on the Help verb. Available options include Modal, |
|
|
Modeless, and Navigate. Modal displays the help items |
|
|
within a modal window if the end user’s browser sup- |
|
|
ports modal windows. If not, a pop-up window displays. |
|
|
Modeless means that a pop-up window displays for |
|
|
every user. Navigate redirects the user to the appropri- |
|
|
ate help page (specified by the HelpUrl property) when |
|
|
he clicks on the Help verb. |
|
HelpUrl |
Used when the HelpMode is set to Navigate. Takes a |
|
|
String value that specifies the location of the page the |
|
|
end user is redirected to when he clicks on the Help verb. |
|
ScrollBars |
Applies scroll bars to the Web Part. Available values |
|
|
include Auto, Both, Horizontal, None, and Vertical. |
|
Title |
Specifies the text for the Web Part’s title. Text appears in |
|
|
the title bar section. |
|
TitleIconImageUrl |
Enables you to apply an icon to appear next to the title |
|
|
by specifying to the icon image’s location as a String |
|
|
value of the property. |
|
TitleUrl |
Specifies the location to direct the end user when the |
|
|
Web Part’s title Web Part is clicked. When set, the title is |
|
|
converted to a link; when not set, the title appears as |
|
|
regular text. |
|
Zone |
Allows you to refer to the zone in which the Web Part is |
|
|
located. |
|
|
|
321
Chapter 10
Summar y
This chapter introduced you to the Web Part Manager, Web Part Zone, and the Web Part controls. Not only do these controls allow for easy customization of the look and feel of either the Web Parts or the zones in which they are located, but you can also use the framework provided to completely modify the behavior of these items.
Personally, I find the Portal Framework to be one of the more exciting new features of ASP.NET 2.0. I like the idea of creating completely modular and customizable Web pages. End users like this feature, and it is quite easy for developers to implement. Just remember that you don’t have to implement every feature explained in this chapter, but with the framework provided, you can choose only the functionality that you want.
322
