最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

is there a way to set an asp.net session variable from a javascriptjquery link? - Stack Overflow

programmeradmin2浏览0评论

Basically i am trying to set a session when a user clicks a specific button is this possible?

So i need to set this session

Session("TenHolStDateNewCheck") = "%"

When this link is clicked

<a href="availability.aspx" class="sidelink">blahblah</a>

thanks

Jamie

Basically i am trying to set a session when a user clicks a specific button is this possible?

So i need to set this session

Session("TenHolStDateNewCheck") = "%"

When this link is clicked

<a href="availability.aspx" class="sidelink">blahblah</a>

thanks

Jamie

Share Improve this question edited Sep 9, 2010 at 14:40 Jamie Taylor asked Sep 9, 2010 at 14:35 Jamie TaylorJamie Taylor 3,53022 gold badges69 silver badges100 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 18

You need a server side code to set session, use $.ajax() function

Using jQuery with ASP.NET

You can use something like this:

Server side (C#)

public partial class _Default : Page 
{
  [WebMethod]
  public static void SetSession()
  {
    ...
  }
}

Client side (aspx)

$.ajax({
  type: "POST",
  url: "Default.aspx/SetSession",
  data: "{}",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  success: function() {
    alert('SetSession executed.');
  }
});

You could do it with a ajax call to a page that sets the session variable of choice to whaterver you send along with the ajax call

See: jQquery Ajax

You can implement JSON-RPC set_session_var method and then in JQuery with $.ajax send json-rpc request to set_session_var method.

发布评论

评论列表(0)

  1. 暂无评论