Documentation for: ASP.NET Ajax Version 1.0

This documentation is for a previous version. For the current released version, see the ASP.NET Ajax documentation on MSDN.

 

 

 

 

 

 

 

Skip Navigation Links.
Tutorials
Sample ASP.NET AJAX Application
ASP.NET AJAX and JavaScript
Extending JavaScript with ASP.NET AJAX
Creating Custom Client Script in ASP.NET AJAX
Dynamically Assigning ASP.NET AJAX Script References
Globalizing a Date by Using Client Script
Embedding a JavaScript File as a Resource in an Assembly
Embedding Localized Resources for a JavaScript File
Adding Localized Resources to a JavaScript File
Creating Custom Client Events
The UpdatePanel Control
Introduction to the UpdatePanel Control
Creating a Simple ASP.NET Page with Multiple UpdatePanel Controls
Using the UpdatePanel Control with Data-Bound Controls
Using the UpdatePanel Control with Master Pages
Using the UpdatePanel Control with User Controls
Using the UpdatePanel Control with a Web Service
Customizing Error Handling for UpdatePanel Controls
Animating UpdatePanel Controls
Canceling an Asynchronous Postback
Giving Precedence to a Specific Asynchronous Postback
Working with PageRequestManager Events
The UpdateProgress Control
Introduction to the UpdateProgress Control
Programming UpdateProgress Controls in Client Script
The Timer Control
Introduction to the Timer Control
Using the Timer Control with Multiple UpdatePanel Controls
ASP.NET Application Services
Using Forms Authentication
Using Profile Information
Web Services
Exposing Web Services to Client Script
Calling Web Services from Client Script
ASP.NET AJAX Extensibility
Creating Custom ASP.NET AJAX Non-Visual Client Components
Creating Custom ASP.NET AJAX Client Controls
Creating an Extender Control
Adding Client Capabilities to a Web Server Control
Creating a Client Component Class Using the Prototype Model
Defining Custom Component Properties and Raising PropertyChanged Events
Releasing Component Resources

Using Profile Information with ASP.NET AJAX

Introduction

The Microsoft ASP.NET 2.0 AJAX Extensions profile service enables you to use the ASP.NET profile application service in  applications. You can access profile data by using ECMAScript (JavaScript) code that accesses a client representation of the profile.

Enabling the Profile Service

To use the profile service from script, you must enable the profile service by using the following element in the application's Web.config file. For more information, see Configuring ASP.NET AJAX.

<system.web.extensions>
  <scripting>
    <webServices
      < profileService enabled="true" />
    </webServices
  </scripting>
</system.web.extensions>

By default, no profile properties are available. For each profile property that you want to make available in a client application, add the property name to the readAccessProperties attribute of the <profileService> element. Similarly, for each server profile property that can be set based on data sent from a client application, add the property name to the writeAccessProperties attribute. The following example shows how to expose individual properties.

<profileService enabled="true" 
  readAccessProperties="Backgroundcolor,Foregroundcolor" 
  writeAccessProperties=" Backgroundcolor,Foregroundcolor"/>

You define the profile properties in the <profile> section by using syntax like that in the following example. For grouped properties, use the <group> element.

<profile enabled="true">
  <add name=" Backgroundcolor" type="System.String"
     defaultValue="white" />
  <add name=" Foregroundcolor" type="System.String"
     defaultValue="black" />
  <properties>
    <group name="Address">
     <add name="Street" type="System.String" />
     <add name="City" type="System.String"/>
     <add name="PostalCode" type="System.String" />
    </group>
  </properties>
</profile>

Example

The following example shows how to use the profile service from client script. The example consists of an ASP.NET Web page that contains an ScriptManager control. When this control is included on the page, the AuthenticationService object is automatically available to any client script in the page.

The page contains a login button with an associated event handler named OnClickLogin. Code in the method calls the login method of the AuthenticationService object.

After you are logged in, the loginComplete callback function is called, which calls the load method of the ProfileService object to load the profile for the current user.

The profile information consists of background and foreground colors that you can set after you are logged in. The background and foreground colors are profile properties you must set in the Web.config file. To define these properties, add the following elements to the application's Web.config file:

<profile enabled="true">
  <properties>
    <add name="Backgroundcolor" type="System.String"
       defaultValue="white"/>
    <add name="Foregroundcolor" type="System.String"
       defaultValue="black"/>
  </properties>
</profile>

The example code provides asynchronous completed callback functions for the load and save methods. You can also add failed callback functions for the load and save methods.

note

Before you run the example, make sure that there is at least one user defined in the application's membership database. For information about how to create a user in the default SQL Server Express Edition database, see Using Forms Authentication.