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...

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.