views:

77

answers:

1

I have the following code invoked from a button click - js event

function onOkReason() {
     alert("called");
     var session = $('<%=Session["A"]%>');
     if (session == null) {
         <%Session["A"]%> = "1";
         alert("1");
     }
     else {
         <%Session["A"]%> = null;
         alert("2");
     }

     alert(session);

 }

It does not seem to work...Any pointers as to what may be wrong...

+4  A: 

The <% %> is evaluated when the page is processed on the server, you can't then set it from the client - it's to late, the page has been processed and sent back to the clients browser.

You'll need to post back to the server (either full or an AJAX call) to set the data.

Kieron
Do you have any code snippets you could post me here...
chugh97