===后台代码====
 public partial class SessionWebForm : System.Web.UI.Page
public partial class SessionWebForm : System.Web.UI.Page {
{ [AjaxPro.AjaxMethod]
    [AjaxPro.AjaxMethod] public static bool SetSession(string name, string value)
    public static bool SetSession(string name, string value) {
    { HttpContext.Current.Session[name] = value;
        HttpContext.Current.Session[name] = value; return true;
        return true; }
    }
 [AjaxPro.AjaxMethod]
    [AjaxPro.AjaxMethod] public static string GetSession(string name)
    public static string GetSession(string name) {
    { return HttpContext.Current.Session[name].ToString();
        return HttpContext.Current.Session[name].ToString(); }
    }
 protected void Page_Load(object sender, EventArgs e)
    protected void Page_Load(object sender, EventArgs e) {
    { AjaxPro.Utility.RegisterTypeForAjax(typeof(SessionWebForm));
        AjaxPro.Utility.RegisterTypeForAjax(typeof(SessionWebForm)); }
    } }
}
====前台=====
 <!-- content -->
<!-- content -->
 <p>If you want to access the session collection you have to use the HttpContext instead of the page property.</p>
<p>If you want to access the session collection you have to use the HttpContext instead of the page property.</p>
 <pre class="codeSample">public partial class SessionWebForm : System.Web.UI.Page
<pre class="codeSample">public partial class SessionWebForm : System.Web.UI.Page {
{ [AjaxPro.AjaxMethod]
  [AjaxPro.AjaxMethod] public static bool SetSession(string name, string value)
  public static bool SetSession(string name, string value) {
  { HttpContext.Current.Session[name] = value;
    HttpContext.Current.Session[name] = value; return true;
    return true; }
  }
 [AjaxPro.AjaxMethod]
  [AjaxPro.AjaxMethod] public static string GetSession(string name)
  public static string GetSession(string name) {
  { return HttpContext.Current.Session[name].ToString();
    return HttpContext.Current.Session[name].ToString(); }
  }
 protected void Page_Load(object sender, EventArgs e)
  protected void Page_Load(object sender, EventArgs e) {
  { AjaxPro.Utility.RegisterTypeForAjax(typeof(SessionWebForm));
    AjaxPro.Utility.RegisterTypeForAjax(typeof(SessionWebForm)); }
  } }</pre>
}</pre>
 <p>Click <a href="javascript:setSession();void(0);">here</a> to set a session value and <a href="javascript:getSession();void(0);">here</a> to get the value back from server-side code. Try to reload this page (using Internet Explorer press F5) and click on the second link to see if you get the same value!</p>
<p>Click <a href="javascript:setSession();void(0);">here</a> to set a session value and <a href="javascript:getSession();void(0);">here</a> to get the value back from server-side code. Try to reload this page (using Internet Explorer press F5) and click on the second link to see if you get the same value!</p>
 <script type="text/javascript">
<script type="text/javascript">
 function setSession() {
function setSession() { SessionWebForm.SetSession("test", new Date().toLocaleString(), function(res){
    SessionWebForm.SetSession("test", new Date().toLocaleString(), function(res){ if(res.error != null) {
        if(res.error != null) { alert(res.error.Message);
            alert(res.error.Message); return;
            return; }
        } alert("Session value is set to '" + res.request.args.value + "'");
        alert("Session value is set to '" + res.request.args.value + "'"); });
    }); }
}
 function getSession() {
function getSession() { SessionWebForm.GetSession("test", function(res){
    SessionWebForm.GetSession("test", function(res){ if(res.error != null) {
        if(res.error != null) { alert(res.error.Message);
            alert(res.error.Message); return;
            return; }
        } alert("Session value = " + res.value);
        alert("Session value = " + res.value); });
    }); }
}
 </script>
</script>
 <!-- end of content -->
<!-- end of content --> 
                     
                    
                 
                    
                 
                
 
 
        

 
     
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号