How to set a Session Variable via JavaScript

Jak
Jak
Member
352 Points
151 Posts

Hi,

 How to set a Session Variable via JavaScript?

Views: 8132
Total Answered: 1
Total Marked As Answer: 0
Posted On: 10-Jul-2015 03:13

Share:   fb twitter linkedin
Answers
Rahul Maurya
Rahul M...
Moderator
1170 Points
210 Posts
     

Hi Jak,

I is not possible to set session variable, directly.

But you can do by using web method on server side and then call the web method from javascript.

In Javascript:

<script type="text/javascript">
 PageMethods.SetSessionValue(txt,val); 
</script>

On server side:

[System.Web.Services.WebMethod] 
public static string SetSessionValue(string txt,string val)
Page objp = new Page();
objp.Session[txt] = val;
 
return "true";
}

 

Must enable page method as:

<asp:scriptmanager ID="Scriptmanager1" EnablePageMethods="true" runat="server"></asp:scriptmanager>
 
Posted On: 11-Jul-2015 04:30
banner

Blog

Active User (0)

No Active User!
 Log In to Chat