Is there any way to assign session value using javascript
i can retrive the value from session but assigning is not working
var TempSession = '<%= Convert.ToInt32(Session["Status"]) %>';
if(TempSession ==6)
{
alert(TempSession );
TempSession =1;
}
JS:-
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"> </script>
<script type="text/javascript">
var TempSession = '<%= Convert.ToInt32(Session["Status"]) %>';
if (TempSession == 6) {
alert(TempSession);
$.ajax({
type: 'POST',
url: 'WebForm1.aspx/SetValue',
data: '{ val:1 }',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (msg) {
alert("New Session value is " + msg.d);
}
});
}
</script>
In your code behind file:-
[WebMethod]
public static string SetValue(string val)
{
HttpContext.Current.Session["Status"] = val;
return HttpContext.Current.Session["Status"].ToString();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With