mck
mck

Reputation: 988

How to access value of session saved from javascript?

I my application i am saving minutes value in session from javascript in a function. My code is

 function redo() {
      .
      .
      .

    '<%Session["mins"] = "' + mins + '";%>';                        
    alert('session min value after is ' + '<%=Session["mins"]%>');

}

Minute value in session is shown in alert but when i access it in code behind

session contains "' + mins + '". My code is

protected void Page_Load(object sender, EventArgs e)
        {
            var aa = Convert.ToInt32(Session["mins"]);
        }

Minutes value is not available in code behind.

How to get session value in code behind ?

Upvotes: 0

Views: 508

Answers (2)

Anuradha Kulkarni
Anuradha Kulkarni

Reputation: 259

Assign the value to a hidden control and access that in JS code

Upvotes: -1

Amadan
Amadan

Reputation: 198476

Session is a serverside concept. The only way(*) for the client to know it is to ask the server (through inclusion in the originally rendered page, or through AJAX).


*) In some realisations of the session concept, the session itself is stored in the cookie, and the client could access and decode it there. This is not reliable, nor recommended, and not available in all frameworks.

Upvotes: 2

Related Questions