08.01.2015 Views

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

Beginning Web Development, Silverlight, and ASP.NET AJAX

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

328<br />

CHAPTER 13 ■ <strong>AJAX</strong> SCRIPTS AND SERVICES<br />

You specify properties by using their name, type, <strong>and</strong> optional default value. So, for<br />

example, to add a couple of properties of type System.String, you could have a setting<br />

like this:<br />

<br />

<br />

<br />

<br />

<br />

<br />

When using <strong>ASP</strong>.<strong>NET</strong> <strong>AJAX</strong>, you now have access to the Sys.Services.ProfileService<br />

service from JavaScript. In the next sections, you’ll see how to use this to access your<br />

custom properties.<br />

Accessing <strong>and</strong> Saving Properties in the Profile<br />

The Profile service offers a load method that you use to read in the properties from the<br />

property store. This is usually called as part of the Login callback, which makes sense—<br />

you want to authenticate the user, <strong>and</strong> then use their validated credentials to load their<br />

profile data.<br />

This takes a number of properties:<br />

propertyNames: String array containing the names of profile properties to load<br />

loadCompletedCallback: Callback function to call upon profile loading<br />

failedCallback: Callback function to call upon failure of profile loading<br />

userContext: String information to pass to the callback functions<br />

For example, a simple call to load will look like this:<br />

Sys.Services.ProfileService.load(null, OnProfileLoadComplete, null, null);<br />

This sets up a simple load of the properties, specifying that the function<br />

OnProfileLoadComplete will be called when the properties are loaded.<br />

The values of the properties are accessed via the Sys.Services.ProfileService.<br />

properties collection. So, if your properties are named Property1 <strong>and</strong> Property2, as used<br />

earlier, you can then use code like this to load their values into a couple of text boxes:<br />

document.form1.txtP1.value = Sys.Services.ProfileService.properties.Property1;<br />

document.form1.txtP2.value = Sys.Services.ProfileService.properties.Property2;

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!