15
Developing Web Applications Using ASP.NET 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 Objectives

14 asp.net session20

Embed Size (px)

Citation preview

Page 1: 14 asp.net session20

Developing Web Applications Using ASP.NET

In this session, you will learn to:Implement asynchronous processing in Web applicationsDescribe the personalization features provided by ASP.NET 2.0Describe ASP.NET 2.0 theme supportImplement personalization featuresAdd themes to a Web applicationImplement customizable themes

Objectives

Page 2: 14 asp.net session20

Developing Web Applications Using ASP.NET

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.

Demo: Optimizing Web Application Performance

Page 3: 14 asp.net session20

Developing Web Applications Using ASP.NET

Solution:To solve this problem, you need to perform the following task:

1. Implement Asynchronous Processing in Web Applicationsa. 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.

Demo: Optimizing Web Application Performance (Contd.)

Page 4: 14 asp.net session20

Developing Web Applications Using ASP.NET

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 typesComplex data structuresClasses 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.

ASP.NET 2.0 Personalization Features

Page 5: 14 asp.net session20

Developing Web Applications Using ASP.NET

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.

ASP.NET 2.0 Personalization Features (Contd.)

Page 6: 14 asp.net session20

Developing Web Applications Using ASP.NET

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.

ASP.NET 2.0 Personalization Features (Contd.)

Page 7: 14 asp.net session20

Developing Web Applications Using ASP.NET

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;

ASP.NET 2.0 Personalization Features (Contd.)

Page 8: 14 asp.net session20

Developing Web Applications Using ASP.NET

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 siteA page and its controlsIndividual 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:

StylesheetsSkinsSupporting images

Theme Support in ASP.NET 2.0

Page 9: 14 asp.net session20

Developing Web Applications Using ASP.NET

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”/>

Theme Support in ASP.NET 2.0 (Contd.)

Page 10: 14 asp.net session20

Developing Web Applications Using ASP.NET

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>

Theme Support in ASP.NET 2.0 (Contd.)

Page 11: 14 asp.net session20

Developing Web Applications Using ASP.NET

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;}

}

Theme Support in ASP.NET 2.0 (Contd.)

Page 12: 14 asp.net session20

Developing Web Applications Using ASP.NET

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.

Demo: Implementing Personalization and Theme in Web Applications

Page 13: 14 asp.net session20

Developing Web Applications Using ASP.NET

Solution:To solve this problem, you need to perform following tasks:

1. Configure Personalizationa. 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 Functionalitya. 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.

Demo: Implementing Personalization and Theme in Web Applications (Contd.)

Page 14: 14 asp.net session20

Developing Web Applications Using ASP.NET

3. Add Themes to the Web Applicationa. Add a Themes folder to the Web applicationb. 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.

4. 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.

Demo: Implementing Personalization and Theme in Web Applications (Contd.)

Page 15: 14 asp.net session20

Developing Web Applications Using ASP.NET

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:

StylesheetsSkinsSupporting images

Summary