您的位置:首页 > 其它

AjaxPro新发现(二):ProfileService

2007-10-16 21:07 253 查看
AjaxPro 同样支持Profile,这意味着完全可以在客户端操作用户自定义数据,只是这个支持得不是很尽如人意,还有秀地方我没有弄明白,还请读者指正

首先,配置Profile

<!--web.config system.web -->

<profile enabled="true">

<properties>

<add name="Hobby" type="System.String" allowAnonymous="true" defaultValue="NullHobby"/>

<add name="Age" type="System.Int32" allowAnonymous="true" defaultValue="0"/>

<group name="Address">

<add name="Province" type="System.String" defaultValue="广东" allowAnonymous="true"/>

<add name="City" type="System.String" defaultValue="广州" allowAnonymous="true"/>

</group>

</properties>

</profile>

<anonymousIdentification enabled="true"/>
.cs文件注册相应的类
public partial class AjaxProProfileService : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)

{

AjaxPro.Utility.RegisterTypeForAjax(typeof(AjaxProProfileService));

AjaxPro.Utility.RegisterTypeForAjax(typeof(AjaxPro.Services.ProfileService));

}

}
这样客户端就会有下面的三个方法:

AjaxPro.Services.Profile.GetProfileProperty(property,callback):property是需要获取的属性名,如果要访问Address.City,需要将property设置为"Address.City",同时这个方法只能得到一个属性值,callback参数result.value就是得到的值
AjaxPro.Services.Profile.SetProfile(json,callback):使用json设置Profile属性,详细参见下面的例子
AjaxPro.Services.Profile.GetProfile(unknowArguments):这个方法应该是获取全部属性的方法,但是试了很久,没有成功,官方的更新资料介绍了这么一段
Version 6.4.26.1

- Added missing enum support for method arguments.

- New test methods in example.aspx need App_Code\enumtest.cs.

- Changed ProfileService, returns now the Profile object. You can access

the properties using res.value.MyProperty (name of the property configured

in web.config). To set a property use res.value.setProperty("MyProperty", "Hello world!").

Setup Profile in your web.config like this example:

<profile>

<properties>

<add name="MyProperty" type="System.String"/>

</properties>

</profile>

function demo_profile() {

var x = AjaxPro.Services.Profile.GetProfile().value;

alert(x.MyProperty);

x.setProperty("MyProperty", "Hello world!");

alert(x.MyProperty);

}

Use AjaxPro.Utility.RegisterTypeForAjax(typeof(AjaxPro.Services.ProfileService));.

- Renamed property IAjaxprocessor.Method to AjaxMethod to be CLSCompliant.

这只我目前找到的关于这个函数的唯一资料,上面的代码运行起来是浏览器直接"假死" ,这个问题只能求助于大家了

客户端例子

function btnSet_onclick() {

AjaxPro.Services.Profile.SetProfile(

{

"Hobby":"FootBall",

"Age":20,

"Address.City":"武汉",

"Address.Province":"湖北"

},

setCallback);

}

function setCallback(result)

{

if(res.error)

{

if(result.value)

{

alert("设置成功");

}

else

{

alert("设置失败");

}

}

else// Error!

{

var msg="出现错误:"+result.error.Message+"\n";

msg+="错误类型"+result.error.Type;

alert(msg);

}

}

function btnGet_onclick() {

AjaxPro.Services.Profile.GetProfileProperty("Address.City",displayHobby);

}

function displayHobby(result)

{

alert(result.value);// alert 武汉

}
显然AjaxPro对ProfileService的支持还不是很完全,下一篇文章将会介绍AjaxPro在客户端编程的相关话题
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: