Wednesday, March 28, 2012

ProfileScriptService Explanation

Hi,

I'm trying to understand and know all new controls Atlas has. By now, I made some examples with AutoCompleteExtender and DragOverlayExtender and all work well.

But, 'm trying to do something with ProfileScriptService and I don't know how it works. I searched information in google, in some blogs for Atlas and found one post in asp.net forum telling about other control in which there is a ProfileScripService control declared. I tested this example but I can't understand the functionality of this control.

Can someone tell me something about ProfileScriptService??

Thanks.

I am in the same boat, I am trying to get the profile script service samples from the presentations on the web to work, but they just don't work. TTYL.

hello.

well, it's just a custom proxy which wraps calls made over a web service defined in the atlas dll. so, what can you do with it? well you can get or save the properties of your profile that have been atlas enabled. to enable a property to be used, you must add it explicitly to the profileService element in the web.config file.

then, on the client side, you get the profile info by calling the load method (btw, you should also add a handler to the loaded event so that you'll be notified when the properties are loaded). to save eventual property changes, you have 2 options: autosave (in this case, you don't have to do anything) or the manual save( calling the save method).

to explain all these aspects, here's a simple example. suppose your asp.net profile has these properties:

<profile enabled="true">
<properties>
<add name="Nome" type="System.String" />
<group name="Morada">
<add name="Rua" type="System.String"/>
<add name="Porta" type="System.String"/>
</group>
</properties>
</profile>

and you want to access all of them on the client side. so, you must also add these lines to activate the atlas profile service:

<profileService
enabled="true"
setProperties="Nome; Morada.Rua;Morada.Porta"
getProperties="Nome; Morada.Rua;Morada.Porta" />

and now, you can build a simple page to get them and change them. here's some simple html that defines the page structure:

<atlas:ScriptManager runat="server" ID="manager" />

<span>Primeiro nome:</span><input type="text" id="nome" />
<br />
<span>Rua:</span><input type="text" id="rua" />
<br />
<span>Porta:</span><input type="text" id="porta" />
<p></p>
<input type="button" id="modificar" value="Actualizar perfil" onclick="actualiza()" disabled="disabled" />

and here's the jscript that might be used with it:

Sys.Application.load.add( onload );
function onload( sender, eventArgs )
{
Sys.Profile.set_autoSave( false );
Sys.Profile.loaded.add( onProfileLoaded );
Sys.Profile.saved.add( onProfileSaved );
Sys.Profile.load();
}

the profile properties are loaded after the page has loaded everything. i've also disabled autosave and set 2 handlers for the loaded and saved events. During the loaded event, i fill the controls; during the saved event, i show an alert which says that everything has been sa

function onProfileLoaded( sender, eventArgs )
{
$("nome").value = Sys.Profile.properties.Nome;
$("rua").value = Sys.Profile.properties["Morada.Rua"];
$("porta").value = Sys.Profile.properties["Morada.Porta"];

$("modificar").disabled = false;
}

function onProfileSaved( sender, eventArgs )
{
alert( "Dados perfil guardados");
}

function actualiza()
{
Sys.Profile.properties["Nome"] = $("nome").value;
Sys.Profile.properties["Morada.Rua"] = $("rua").value;
Sys.Profile.properties["Morada.Porta"] = $("porta").value;

Sys.Profile.save();
}

btw, some important observations:

* the property group sintax must use the [ ] operator
* though you can use this service from xml-script, there's currently several limitations when you have proeprties and subproperties
* pay attention if you use datetime values

No comments:

Post a Comment