Solved

Session value of Asp.net in javascript

Posted on 2006-07-23
7
443 Views
Last Modified: 2008-01-09
Hi Experts

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

For Example

<Script>

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

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

</Script>

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
0
Comment
Question by:Pralad
  • 3
  • 2
7 Comments
 
LVL 30

Expert Comment

by:third
Comment Utility
"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.
0
 
LVL 30

Expert Comment

by:third
Comment Utility
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.
0
 
LVL 1

Author Comment

by:Pralad
Comment Utility
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.
{
}
}
}
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 1

Author Comment

by:Pralad
Comment Utility
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(me.id);
      strText=strText.substr(0,strText.lastIndexOf("_"));
      strText+="_IsDelete";
<      
if(confirm("Are you Sure?"))
{
  document.getElementById(strText).value="True";
}
else
{
   document.getElementById(strText).value="False";
}
}


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.
                     
0
 
LVL 3

Accepted Solution

by:
alecpotts earned 125 total points
Comment Utility
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....

Alec
0
 
LVL 1

Author Comment

by:Pralad
Comment Utility
Hi Alec,

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

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now