有没有办法从 javascript/jquery 链接设置 asp.net 会话变量?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3677582/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 01:54:35  来源:igfitidea点击:

is there a way to set an asp.net session variable from a javascript/jquery link?

javascriptasp.netjquerysession

提问by Jamie Taylor

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

杰米

采纳答案by Karl Johan

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

您可以通过对页面的 ajax 调用来实现,该页面将选择的会话变量设置为随 ajax 调用一起发送的任何内容

See: jQquery Ajax

看: jQquery Ajax

回答by Branimir

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

您需要一个服务器端代码来设置会话,使用$.ajax()函数

Using jQuery with ASP.NET

在 ASP.NET 中使用 jQuery

You can use something like this:

你可以使用这样的东西:

Server side (C#)

服务器端 (C#)

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

Client side (aspx)

客户端 (aspx)

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

回答by jcubic

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

您可以实现 JSON-RPCset_session_var方法,然后在 JQuery 中使用 $.ajax 向set_session_var方法发送 json-rpc 请求。