ie421.NET

面对技术,你别无选择,.NET世界是如此精彩,而我们要做的就是:Thinking More

博客园 首页 新随笔 联系 订阅 管理

原文:http://5878.x5dj.com/GroupForum/5878/00345797.shtml

 

在服务器端page_load
AjaxPro.Utility.RegisterTypeForAjax(typeof(test));
this.Button_Write.Attributes.Add("onclick","WriteSession();");//写session
this.Button_Read.Attributes.Add("onclick", "ReadSession();");//读session


其他写和读的方法
/// <summary>
/// 写session
/// </summary>
/// <param name="str"></param>
[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
public void WriteSession(string str)
{
Session["UserName"] = str;
}
/// <summary>
/// 读session
/// </summary>
/// <returns></returns>
[AjaxPro.AjaxMethod(AjaxPro.HttpSessionStateRequirement.ReadWrite)]
public string ReadSession()
{
string str = "";
if (Session["UserName"] != null)
{
str = Session["UserName"].ToString();
}
return str;
}




客户端代码:
//4、访问Session的值
//写入
function WriteSession()
{
var str = "HAHA";
test.WriteSession(str,CallBack_WriteSession);
}
function CallBack_WriteSession(res)
{
if(res.error == null)
{
alert("OK");
}
else
{
alert(res.error.message);
}
}
//访问
function ReadSession()
{
test.ReadSession(CallBack_ReadSession);
}
function CallBack_ReadSession(res)
{
if(res.error == null)
{
alert(res.value);
}
else
{
alert(res.error.message);
}
}

 

posted on 2008-08-08 09:16  ie421  阅读(307)  评论(0编辑  收藏  举报