Atlas中用Profile Service保存用户信息
下面是一些JavaScript代码,用来相应事件并控制Sys.Profile对象:
function OnLoad() {
Sys.Profile.saved.add(onSaveComplete);
}
function OnSave() {
Sys.Profile.save();
}
function onSaveComplete() {
alert('The profile has been saved.');
}
下面是Atlas的XML脚本。我们可以看到在页面装载完成后,开始执行OnLoad()方法,其中添加了保存profile完成后的事件处理函数。在update按钮被点击时,OnLoad()方法将被执行,将客户端的profile提交回服务器。
<script type="text/xml-script">
<page xmlns:script="http://schemas.microsoft.com/xml-script/2005">
<components>
<profile id="profilecontrol" autoSave="false" />
![]()
<textBox id="txtFirstName" >
<bindings>
<binding dataContext="profilecontrol" dataPath="FirstName" property="text" direction="InOut" />
</bindings>
</textBox>
<textBox id="txtLastName" >
<bindings>
<binding dataContext="profilecontrol" dataPath="LastName" property="text" direction="InOut" />
</bindings>
</textBox>
![]()
<button id="update">
<click>
<invokeMethod target="application" method="OnSave" />
</click>
</button>
![]()
<application id="application" load="OnLoad">
</application>
</components>
</page>
</script>
上面同样需要注意的是我们设定了上述绑定的绑定方向为InOut,这样对input中数据的改变将被自动反射到实际的profile数据中。
OK, 浏览器中测试一下,页面装载: 
Dflying登录后,您可以看到两个input已经填充了我的profile信息: 
修改这两个input的内容,把我升级成Bill Gates。呵呵,一秒钟以内就搞定了。(yy中……) 
0
相关文章