Load method of the profile service, which retrieves a user s settings in .NET framework

Drawer PDF-417 2d barcode in .NET framework Load method of the profile service, which retrieves a user s settings

Listing 5.25 Load method of the profile service, which retrieves a user s settings
Making PDF417 In .NET
Using Barcode creator for ASP.NET Control to generate, create PDF417 image in ASP.NET applications.
www.OnBarcode.com
PDF 417 Maker In VS .NET
Using Barcode creation for ASP.NET Control to generate, create PDF-417 2d barcode image in ASP.NET applications.
www.OnBarcode.com
function loadProfile(){ Sys.Services.ProfileService.load(null, onLoadCompleted, onLoadFailed, null); }
Data Matrix 2d Barcode Drawer In .NET Framework
Using Barcode creation for ASP.NET Control to generate, create ECC200 image in ASP.NET applications.
www.OnBarcode.com
Code 3/9 Generation In .NET
Using Barcode drawer for ASP.NET Control to generate, create Code39 image in ASP.NET applications.
www.OnBarcode.com
Pass null as first parameter
Matrix Encoder In VS .NET
Using Barcode encoder for ASP.NET Control to generate, create Matrix image in ASP.NET applications.
www.OnBarcode.com
Printing Barcode In VS .NET
Using Barcode maker for ASP.NET Control to generate, create Barcode image in ASP.NET applications.
www.OnBarcode.com
function onLoadCompleted(numProperties, userContext, methodName){ var profile = Sys.Services.ProfileService; $get("address1").value = profile.properties.Address1; $get("address2").value = profile.properties.Address2; Read $get("city").value = profile.properties.City; properties $get("state").value = profile.properties.State; $get("zip").value = profile.properties.Zip; }
Barcode Generation In .NET
Using Barcode creation for ASP.NET Control to generate, create Barcode image in ASP.NET applications.
www.OnBarcode.com
Drawing Postnet In .NET
Using Barcode maker for ASP.NET Control to generate, create Delivery Point Barcode (DPBC) image in ASP.NET applications.
www.OnBarcode.com
function onLoadFailed(error, userContext, methodName){ alert(error.get_message()); }
PDF-417 2d Barcode Creator In None
Using Barcode encoder for Excel Control to generate, create PDF-417 2d barcode image in Excel applications.
www.OnBarcode.com
Generate PDF417 In Java
Using Barcode creator for Android Control to generate, create PDF-417 2d barcode image in Android applications.
www.OnBarcode.com
Because you pass in B null as the first parameter, you retrieve all the profile properties that you defined in web.config. Then, when the successful callback function is called, you can C read the properties and populate the form accordingly. Updating profile Updating the user s profile properties is just as easy all you have to do is initialize the values and then call the save function in the service. See listing 5.26.
Reading GTIN - 13 In Visual Basic .NET
Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
Code 3/9 Creation In Java
Using Barcode maker for Java Control to generate, create Code 3 of 9 image in Java applications.
www.OnBarcode.com
Making asynchronous network calls
Code 3/9 Scanner In None
Using Barcode recognizer for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Draw Barcode In None
Using Barcode printer for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
Listing 5.26 Save function, which updates a user s profile information
Make GS1 - 13 In None
Using Barcode generation for Online Control to generate, create EAN-13 Supplement 5 image in Online applications.
www.OnBarcode.com
Encode QR-Code In None
Using Barcode printer for Software Control to generate, create QR Code ISO/IEC18004 image in Software applications.
www.OnBarcode.com
function saveProfile(){ var addr1 = $get("address1").value; var addr2 = $get("address2").value; var city = $get("city").value; var state = $get("state").value; var zip = $get("zip").value; Sys.Services.ProfileService.properties.Address1 = addr1; Sys.Services.ProfileService.properties.Address2 = addr2; Sys.Services.ProfileService.properties.City = city; Sys.Services.ProfileService.properties.State = state; Sys.Services.ProfileService.properties.Zip = zip; Sys.Services.ProfileService.save(null, onSaveCompleted, onSaveFailed, null); } function onSaveCompleted(numProperties, userContext, methodName){ $get("updating").style.display = "none"; } function onSaveFailed(error, useContext, methodName){ alert(error.get_message()); }
Scan DataMatrix In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Code39 Recognizer In Java
Using Barcode reader for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Again, you follow the same pattern of calling the service, passing in the name of callback functions for success or failure, and updating the UI on return. Let s take this a step further by implementing a feature that automatically saves a user s profile as they edit their information. AutoSave pattern The simplicity and nature of this service provide you with a great opportunity: the ability to save user profile settings automatically. With the use of a timer, you can periodically save profile information. This added value will be appreciated by users who lose their Internet connection intermittently or forget to click the Save button on the form (it does happen). To integrate this useful pattern, you kick off the timer after the profile settings are originally loaded. Then, when the interval for the timer elapses, you call the same saveProfile function you used earlier:
Make UCC.EAN - 128 In None
Using Barcode encoder for Office Word Control to generate, create GTIN - 128 image in Microsoft Word applications.
www.OnBarcode.com
GS1 128 Creation In Java
Using Barcode maker for Java Control to generate, create GS1 128 image in Java applications.
www.OnBarcode.com
function onLoadCompleted(numProperties, userContext, methodName){ ... window.setInterval(tryAutoSave, 10000); }
Using ASP.NET application services
function tryAutoSave(){ saveProfile(); }
This is a nice feature that doesn t require a lot of coding. This leads us to the last service, roles, which grants you the ability to inquire about the roles a user has been assigned.
Roles: an Orcas preview
The next version of the ASP.NET AJAX framework will include another built-in application service: roles. The simplest way to demonstrate how to use the role service is to designate a portion of the page that only certain users in a role can view.
NOTE
The built-in roles service isn t part of the 1.0 release of ASP.NET AJAX. This section provides a sneak peek at what is to come in the next version. This version will be baked into the next release of Visual Studio, codenamed Orcas. At the time of this writing, downloads for Orcas are available here: http://msdn2.microsoft.com/en-us/vstudio/aa700831.aspx.
Before we begin, update the web.config file for this service by adding another section for the service under the sectionGroup area:
<sectionGroup name="webServices"... ... <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="false" allowDefinition="MachineToApplication"/>
Next, you need to enable the service along with the others:
<system.web.extensions> <scripting> <webServices> ... <roleService enabled="true" /> </webServices> </scripting> </system.web.extensions>
That s all you need for the configuration portion. For the UI, add a div element named adminView to the contact information page. By default, you hide this element by setting its display style to none:
<div id="adminView" style="display: none;"> <b>Only admins can see this message!</b> </div>
Making asynchronous network calls
After the page loads, you can retrieve the current user s roles and make the adminView element visible if they re in the designated role:
function pageLoad(){ $get("address1").focus(); ... loadRoles(); } function loadRoles(){ Sys.Services.RoleService.load(onLoadRolesCompleted, onLoadRolesFailed, null); }
Call load function
function onLoadRolesCompleted(result, userContext, methodName){ if (Sys.Services.RoleService.isUserInRole("Admin")){ $get("adminView").style.display = "block"; } Call isUserInRole }
Copyright © OnBarcode.com . All rights reserved.