This way
Client Side
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type = "text/javascript">
function SetSession() {
var value = '237';
$.ajax({
type: "POST",
url: "CS.aspx/SetSession",
data: '{value: "' + value + '" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
}
});
}
function OnSuccess(response) {
alert(response.d);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<input type = "button" value = "Set Session" onclick = "SetSession()" />
</form>
</body>
</html>
Code
[WebMethod]
public static void SetSession(string value)
{
HttpContext.Current.Session["Value"] = value;
}