4

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

3 Answers 3

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.');
  }
});
Sign up to request clarification or add additional context in comments.

3 Comments

I don't really understand how to do this can you give an example
Look at examples on linked site
This worked great even after these years thanks @Branimir
3

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

1 Comment

I really have to say that Branimir's answer has more information and should really be the accepted one or at least get an up vote
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.