zoukankan      html  css  js  c++  java
  • ajax.net中操作session

    在服务器端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);
        }
    }

  • 相关阅读:
    结合自己造的轮子实践按需加载
    清风不知道--项目需求分析
    2020软件工程作业——团队03
    2020软件工程作业——团队02
    清风不知道——团队展示
    Java注解
    Java反射机制
    浅谈Vector
    浅谈LinkedList
    在IDEA中搭建Java源码学习环境并上传到GitHub上
  • 原文地址:https://www.cnblogs.com/wucf2004/p/582890.html
Copyright © 2011-2022 走看看