Session value of in javascript

Hi Experts

Is there any method to change the session variable value in the javascript.

For Example


var ses=b'<%=Session("ConfirmDelete")%>';
alert('Session1  ' +ses);

<%Session("ConfirmDelete")=%> ='Hello';
var ses='<%=Session("ConfirmDelete")%>';
alert('Session2  ' +ses);


Here in the first case ses is storing the value  "<%=Session("ConfirmDelete")%>" instead of the value of the session variable "ConfirmDelete"

Similaryly while I wish to assign value to the session it throughs error.

could someone help me with appropriate suggestion.

Thanks in advance
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

"Is there any method to change the session variable value in the javascript."

No, session variable is processed server-side while javascript is client-side.
if you want to change the value of your session variable, you can send the javascript value as a querystring or pass it on a form field and then catch it server-side. in other words, you need to postback to the server in order for the session variable changed.
PraladAuthor Commented:
I am using javascript and server script(codebehind). I wish to capture the value of confirm message before execution of the codbehind.
I tried using hidden text box and doing this activity but the value of the hiddentext box is reset to null as its getting initialized again.

I am unable to avoid reinitialization of the variable. Its declared this way

 public class UnitList : Com.ParagonCIS.Framework.Web.Controls.BaseList
  protected TextBox TxtIsDelete;


    private void linkDeleteButton_Click(object sender, EventArgs e)
if TxtIsDelete.Value=="True"               - Here value is not available as control is reinitalized.
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

PraladAuthor Commented:
the link buttons client event method initializes the textbox value to true if confirmation is clicked else it is initialized to false.  Declaration part of the linkDeletbutton is below

  linkDeleteButton = new System.Web.UI.WebControls.LinkButton();
  linkDeleteButton.ID = "Del" + UnitsLinkStack.ID.ToString();
  linkDeleteButton.OnClientClick = "DeleteMe(this)";

and related java script is below

function DeleteMe(me)
var strText=new String(;
if(confirm("Are you Sure?"))

Over here its value is set to true when confirmation is given as yes but once it comes to codebehind script the textbox values is lost as textbox is reinitailized.
Hi there,

Since your textbox value is being re-initialised and the value lost, why not put the value of your textbox into a hidden field, and then retreive the value of the hidden field in your code-behind?

If the script blocik you posted above is located in an ASPX file, then your code should work - I think the problem is more likely one of syntax than anything else. Certainly when the page is loading, you should be able to context switch and grab a value from server side. If you can't access the session object directly from your script, try putting the session value in a local variable or constant, and then accessing that...

If on the other hand the script is in a seperate JS file, then that won't work at all..! The context switching only works if you do it in the ASPX file.

Hope that helps....


Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
PraladAuthor Commented:
Hi Alec,

Thanks for the way to the solutions. Sorry for delared response.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.