5,550,131 members and growing! (19,209 online)
Email Password   helpLost your password?
Web Development » ASP.NET » General     Intermediate

User Personalization/Profile with Microsoft AJAX Library (aka Atlas Client Library)

By Patrick Spieler

This article does explain, howto use ASP.NET 2.0 Profile Service together with the Microsoft AJAX Library to personalize a Web-Application
Windows, .NET, Visual Studio, ASP.NET, Dev

Posted: 20 Sep 2006
Updated: 20 Sep 2006
Views: 14,608
Bookmarked: 20 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
8 votes for this Article.
Popularity: 3.67 Rating: 4.07 out of 5
1 vote, 12.5%
1
1 vote, 12.5%
2
0 votes, 0.0%
3
1 vote, 12.5%
4
5 votes, 62.5%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Sample Image - ProfileWithAtlas.jpg

Introduction

This article/demo will show you, how you can access and use the powerfull ASP.NET 2.0 Profile Service with the Microsoft AJAX Library (aka ATLAS client-side Framework; read this article about Atlas Naming and Roadmap).

ASP.NET 2.0 Profile Service is based on the Provider-Model - so you can configure and exchange the datastore. More details about Profiles and Personalization here.

This example here does use the drag&drop features available with the Microsoft AJAX Library. It will allow positioning an image-object where ever you want on the current page just by draging it. An excellent article about this feature here on CodeProject.

The current position of the image will be instantly persisted (by default, profile service does use SQLServer Express Edition). As soon as the user does re-open the page, the image will appear at the same position the image was dragged the last time by the user.

Web.Config

First, we have to configure and to activate several services. The ASP.NET 2.0 Profile Service is accessible thru a WebService, so we have to enable this feature.

Further, poxTop and poxLeft values have to be declared inside <Profile> Section (to tell ASP.NET that this attributes go into the profile) as well as inside <profileService>-Section (to tell ASP.NET which attributes are accessbile for the AJAX Stuff).

Last important step is to remap *.asmx (WebServices) with the ScriptHandlerFactory Handler to make WebServices available via JavaScript. 

<?xml version="1.0"?>
<configuration>
 <configSections>
  <sectionGroup name="microsoft.web" type="Microsoft.Web.Configuration.MicrosoftWebSectionGroup">
   <section name="webServices" type="Microsoft.Web.Configuration.WebServicesSection" requirePermission="false"/>
   <section name="profileService" type="Microsoft.Web.Configuration.ProfileServiceSection" requirePermission="false"/>
  </sectionGroup>
 </configSections>

 <microsoft.web>
  <!-- Enable WebServices because Profile-Service ASP.NET is accessible thru WS -->
  <webServices enableBrowserAccess="true"/>
  
  <profileService 
   enabled="true" 
   setProperties="poxTop;poxLeft;" 
   getProperties="poxTop;poxLeft;">
  </profileService>
  
 </microsoft.web>
 
 <system.web>
  <authentication mode="Windows"/>
  <profile enabled="true">
   <properties>
    <add name="poxTop" type="integer"/>
    <add name="poxLeft" type="integer"/>
   </properties>
  </profile>
  <pages>
   <controls>
    <add namespace="Microsoft.Web.UI" assembly="Microsoft.Web.Atlas" tagPrefix="atlas"/>
    <add namespace="Microsoft.Web.UI.Controls" assembly="Microsoft.Web.Atlas" tagPrefix="atlas"/>
   </controls>
  </pages>
  <compilation debug="true" />

  <httpHandlers>
   <remove verb="*" path="*.asmx"/>
   <!-- ASMX is mapped to a new handler so that proxy javascripts can also be served. -->
   <!-- Otherwise, you get the following error  -->
   <!-- The HTTP verb POST used to access path  -->
   <!-- '/ProfileWithAtlas/ScriptServices/Microsoft/Web/Services/Standard/ProfileWebService.asmx' is not allowed. -->
   <add verb="*" path="*.asmx" type="Microsoft.Web.Services.ScriptHandlerFactory" validate="false"/>
  </httpHandlers>


 </system.web>

</configuration>

*.aspx Page

Inside the WebPage, we tell the ScriptManager to include a reference to the AtlasUIDragDrop library to enable this feature.

    <atlas:ScriptManager runat="server" ID="ScriptManager1">
        <Scripts>
            <atlas:ScriptReference ScriptName="AtlasUIDragDrop" />
        </Scripts>
    </atlas:ScriptManager>

Next, we declare the object we want to drag. By placing an image- inside a div-tag and by setting the div-id to "imagePanel", we set-up the structure. The whole construct we put into a html-table.

        <table cellpadding="0" cellspacing="0"  border="0">
            <tr>
                <!-- This fixed Size is important. Without it, your d&d will not snapp-in -->
                <td style="width:200px;height:600px"></td>
                <td>
                    <div id="imagePanel">
                        <img id="dragHandler" src="smile.gif" alt="Smile!" />
                    </div>
                </td>
                
            </tr>
        </table>

The following XML-Script does attach the drag&drop feature the "imagePanel" div-tag.

The "OnMove" method will be called after the user has moved (or draged) the image. We can handle this event later via JavaScript.

    
    <script type="text/xml-script">
        <page xmlns:script="http://schemas.microsoft.com/xml-script/2005">http://schemas.microsoft.com/xml-script/2005">

            <components>
                <control id="imagePanel">
                    <behaviors>
                        <floatingBehavior handle="dragHandler" move="OnMove" />
                    </behaviors>
                </control>
            </components>
        </page>
    </script>

Last thing to do is to program the client-stuff in JavaScript with the support of the AJAX Library.

Inside the pageLoad() event, we attach two event-handlers (onProfileLoadComplete, onProfileSaveComplete) and we load the current user profile. After the Profile is loaded, we arrive inside the onProfileLoadComplete-event where we use the poxTop and poxLeft position to do the re-positioning of the image.

The onMove-event is attached and fired as explained above. As soon as the user do repositioning, we save back the new x- and y-postitions to the persisten medium.

For debugging purpose, the onProfileSaveComplete-event is attachend to display the last time the profile-data is saved inside the browsers statusbar. 

    <script type="text/javascript">
        function pageLoad()
        {
            Sys.Profile.set_autoSave(false);
            Sys.Profile.loaded.add(onProfileLoadComplete);
            Sys.Profile.saved.add(onProfileSaveComplete); 
            Sys.Profile.load(); 
        }
        
        function onProfileLoadComplete() 
        {      
            var objStyle = $object('imagePanel').element.style;
            if (Sys.Profile.properties.poxTop != null)
                objStyle.posTop = Sys.Profile.properties.poxTop;
            if (Sys.Profile.properties.poxLeft != null)
                objStyle.posLeft = Sys.Profile.properties.poxLeft;
        }
        
        function onProfileSaveComplete()
        {
            window.status = "Profile saved: " + Date();
        }
        
        function OnMove(sender, cancelArgs)
        {
            var ele = sender.control.element;
            Sys.Profile.properties.poxTop = ele.offsetTop;
            Sys.Profile.properties.poxLeft = ele.offsetLeft;
            Sys.Profile.save();
        }
    </script>

 

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Patrick Spieler


Consultant for Trivadis AG in Switzerland.
Interested in .NET, Architectures, Patterns and Web 2.0.
Blog and articles at http://sharpcuts.blogspot.com
Occupation: Web Developer
Location: Switzerland Switzerland

Other popular ASP.NET articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 2 of 2 (Total in Forum: 2) (Refresh)FirstPrevNext
Subject  Author Date 
GeneralHow to get it working on Microsoft ASP.NET 2.0 AJAX Futures December CTP and Extenstions 1.0memberheaddeball18:26 21 Jan '07  
GeneralNice articlemembervik2020:15 20 Sep '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 20 Sep 2006
Editor:
Copyright 2006 by Patrick Spieler
Everything else Copyright © CodeProject, 1999-2008
Web18 | Advertise on the Code Project