You are on page 1of 15

Developing Web Applications Using ASP.

NET
Objectives

In this session, you will learn to:
Implement asynchronous processing in Web applications
Describe the personalization features provided by ASP.NET
2.0
Describe ASP.NET 2.0 theme support
Implement personalization features
Add themes to a Web application
Implement customizable themes

Ver. 1.0 Slide 1 of 15
Developing Web Applications Using ASP.NET
Demo: Optimizing Web Application Performance

Problem Statement:
You are a developer in the Adventure Works organization, a
fictitious bicycle manufacturer. You have been asked to assist
in creating a new Business-to-Consumer (B2C) Web
application and a related Business-to-Employee (B2E) extranet
portal.
Decisions on the design of the application have already been
made. You have been asked to carry out a number of specific
tasks in order to implement various elements of this design. As
part of the first phase of the B2C development, you have been
asked to prototype various performance related techniques for
the Web application.

Ver. 1.0 Slide 2 of 15
Developing Web Applications Using ASP.NET
Demo: Optimizing Web Application Performance (Contd.)

Solution:
To solve this problem, you need to perform the following task:
1. Implement Asynchronous Processing in Web Applications
a. Enable asynchronous processing on a page.
b. Add asynchronous event handlers for calling a Web service and
receiving data from the Web service.
c. Test the asynchronous calling of the Web service.

Ver. 1.0 Slide 3 of 15
Developing Web Applications Using ASP.NET
ASP.NET 2.0 Personalization Features

ASP.NET provides profiles for easy implementation of
personalization in a Web site.
Profiles consist of a set of named properties that are stored
for each user. These properties can be:
Simple data types
Complex data structures
Classes from the .NET Framework
Profiles can be used to store user specific information.
The profile system has been designed to keep the data in
the profiles independent of the storage location of the
profiles. This separation is achieved by using profile
providers.

Ver. 1.0 Slide 4 of 15
Developing Web Applications Using ASP.NET
ASP.NET 2.0 Personalization Features
(Contd.)

Profile providers:
A profile provider enables ASP.NET to store and retrieve
profiles by using a common API, regardless of the underlying
data storage mechanism.
The default provider is the
System.Web.Profiles.SQLProfileProvider class,
which uses Microsoft SQL Server as its storage mechanism.
To use the default provider, you must create a suitable
database on the computer running SQL Server. You can do
this by using the regsql.exe tool.
A custom profile provider can also be created, in case profiles
need to be stored in a database other than Microsoft SQL
Server.

Ver. 1.0 Slide 5 of 15
Developing Web Applications Using ASP.NET
ASP.NET 2.0 Personalization Features
(Contd.)

Configuring Profile properties:
The properties that need to be stored in each user profile for
an application can be configured in the Web.config file:
<System.web>
<anonymousIdentification enabled=“true”/>
<profile>
<properties>
<add name = “PrefPaymentMethod”
type =“System.String”
allowAnonymous=“true”/>
</properties>
</profile>
</System.web>
Profiles can be used even when the user is not authenticated.

Ver. 1.0 Slide 6 of 15
Developing Web Applications Using ASP.NET
ASP.NET 2.0 Personalization Features
(Contd.)

Getting and Setting Profile Properties:
Profile properties can be accessed by using the Profile
object.
A value can be stored in a property of the Profile object as:
Profile.PrefPaymentMethod =
ddPrefPaymentMethod.SelectedValue;
A value of a property can be retrieved from the Profile
object as:
lblPrefPaymentMethod = Profile.PrefPaymentMethod;

Ver. 1.0 Slide 7 of 15
Developing Web Applications Using ASP.NET
Theme Support in ASP.NET 2.0

A theme is a collection of property settings.
Themes are used to define the look of pages and controls
and apply the look consistently across pages.
Theme settings can be applied to any of the following:
The entire Web site
A page and its controls
Individual controls
Multiple themes can be created to enable users to choose
their preferred appearance for the Web site.
An ASP.NET theme consist of the following objects:
Stylesheets
Skins
Supporting images

Ver. 1.0 Slide 8 of 15
Developing Web Applications Using ASP.NET
Theme Support in ASP.NET 2.0 (Contd.)

Themes are stored in the App_Themes folder within an
application.
To create a theme, you need to:
1. Add a subfolder with the same name as the name of the
theme to the App_Themes folder.
2. Add stylesheets, skins, and supporting image files to the folder
created.
To create a skin, you need to:
1. Create a theme folder under the App_Themes folder.
2. Add a skin file to the theme folder.
3. Add an entry to the skin file for each class of controls to which
you want to apply the theme. For example:
<asp:Label runat=“server” Forecolor=“red”/>
<asp:Button runat=“server” backcolor=“yellow”
bordercolor=“Blue”/>

Ver. 1.0 Slide 9 of 15
Developing Web Applications Using ASP.NET
Theme Support in ASP.NET 2.0 (Contd.)

Applying a Theme:
A theme can be specified for a particular page by using the <
%@Page%> directive as:
<%@ Page Theme = “BlueSky”%>
A theme can be specified for the entire application in the root
Web.config file as:
<configuration>
<system.Web>
<pages theme =“BlueSky”/>
</system.web>
</configuration>

Ver. 1.0 Slide 10 of 15
Developing Web Applications Using ASP.NET
Theme Support in ASP.NET 2.0 (Contd.)

Enabling Users to Personalize Themes:
Themes can be used to enable users to personalize the
application.
The theme stored in a user’s profile can be set
programmatically as each page loads.
Theme must be set before or during Page_PreInit event
handler as:
void Page_PreInit(object sender, EventArgs e)
{
switch (Request.QueryString[“theme”])
{
case “Theme1”: Page.Theme = “Theme1”; break;
case “Theme2”: Page.Theme = “Theme2”; break;
}
}

Ver. 1.0 Slide 11 of 15
Developing Web Applications Using ASP.NET
Demo: Implementing Personalization and Theme in Web
Applications

Problem Statement:
You are a developer in the Adventure Works organization, a
fictitious bicycle manufacturer. You have been asked to assist
in creating a new Business-to-Consumer (B2C) Web
application and a related Business-to-Employee (B2E) extranet
portal.
Decisions on the design of the application have already been
made. You have been asked to carry out a number of specific
tasks in order to implement various elements of this design. As
part of the first phase of the B2C development, you have been
asked to prototype personalization and themes for registered
members of the Web site.

Ver. 1.0 Slide 12 of 15
Developing Web Applications Using ASP.NET
Demo: Implementing Personalization and Theme in Web Applications
(Contd.)

Solution:
To solve this problem, you need to perform following tasks:
1. Configure Personalization
a. Open the starter solution.
b. Add a connection string for the profile system.
c. Add personalization providers.
d. Add personalization properties.
e. Control anonymous identification.
2. Implement Personalization Functionality
a. Review the UpdateProfile.aspx page.
b. Retrieve profile data at run time.
c. Update profile data at run time.
d. Test the profile functionality of the Web site.

Ver. 1.0 Slide 13 of 15
Developing Web Applications Using ASP.NET
Demo: Implementing Personalization and Theme in Web Applications
(Contd.)

3. Add Themes to the Web Application
a. Add a Themes folder to the Web application
b. Add the DefaultBlue theme to the Web application.
c. Create a definition for a default button.
d. Create a definition for a default text box.
e. Create a definition for an alternative button.
f. Use the DefaultBlue theme.
3. Implement Personalized Themes
a. Add a personalized theme property.
b. Add user interface elements for selecting themes.
c. Add code for storing and retrieving the selected theme.
d. Add code for applying the selected theme.
e. Test the personalized theme functionality.

Ver. 1.0 Slide 14 of 15
Developing Web Applications Using ASP.NET
Summary

In this session, you learned that:
An ASP.NET profile consists of a set of named properties that
are stored for each user.
A profile provider enables ASP.NET to store and retrieve
profiles by using a common API, regardless of the underlying
data storage mechanism.
A theme is a collection of property settings that enable user to
define and apply the look of pages and controls consistently
across the pages.
An ASP.NET theme consists of the following objects:
Stylesheets
Skins
Supporting images

Ver. 1.0 Slide 15 of 15