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.
这只我目前找到的关于这个函数的唯一资料,上面的代码运行起来是浏览器直接"假死" ,这个问题只能求助于大家了
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在客户端编程的相关话题
首先,配置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在客户端编程的相关话题
相关文章推荐
- 今天很兴奋,发现了一个 ajaxpro 经常发生的错误,哈哈
- 使用AjaxPro.AjaxProperty的小发现
- AjaxPro新发现-错误处理
- AjaxPro在ASP.NET中的应用简介
- 用AjaxPro实现无刷新翻页效果及数据库分页技术介绍
- (转)AjaxPro实现机制探讨——Ajax是如何调用服务器端C#方法?
- 使用ajaxpro.net的步骤
- 温故AjaxPro系列之三(类型处理)
- 如何在 AjaxPro.net的AjaxMethod中使用session和cookie(转)
- ASP.NET AjaxPro的应用
- 如何在AjaxPro.net的AjaxMethod中使用session和cookie
- AjaxPro 内部机制探讨
- Ajaxpro.dll 配置及使用
- ajaxpro中文乱码问题解决方案
- AjaxPro应用之DataSet
- ajaxPro.dll基础教程 (.net1.0)
- 使用AjaxPro.dll文件实现简单Ajax应用
- ajaxpro的ajax函数内不能使用session
- AjaxPro.Utility.RegisterTypeForAjax DropDownList三级联动
- ajaxPro.dll用法解析