Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Access session variables in javascript

Reply
Thread Tools

Access session variables in javascript

 
 
indkids indkids is offline
Junior Member
Join Date: Feb 2012
Posts: 1
 
      02-22-2012
I'm trying to catch when a user makes a change to a form without recalculating totals. I set a session variable when they make a change and reset it when they recalculate. The changes and recalculating are done without a postback so I cannot use a hidden field. I have window.onbeforeunload = confirmExit; on my page.

In my code I'm using:
Dim csname AsString = "csconfirmExit"
Dim cstype As Type = Me.GetType()

' Get a ClientScriptManager reference from the Page class.
Dim cs As ClientScriptManager = Page.ClientScript
' Check to see if the client script is already registered.
If (Not cs.IsClientScriptBlockRegistered(cstype, csname)) Then
Dim cstext2 AsNew StringBuilder()
cstext2.Append(
"<script type=""text/javascript""> function confirmExit() {")
cstext2.Append(
" var a; a='<%= Session(""DetailsModified"") %>'; if (a == ""True"")")
cstext2.Append(
" return ""Recalculate"" } </")
cstext2.Append("script>")
cs.RegisterClientScriptBlock(cstype, csname, cstext2.ToString)
EndIf

The problem is a is not being evaluated it is the literal <%= Session("DetailsModified") %>.

How can I access a session variable dynamically through javascript. I cannot evaluate it when the page loads because as I said it changes without a postback.

Thanks!
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Put variables into member variables or function variables? tjumail@gmail.com C++ 9 03-23-2008 04:03 PM
Session Variables and Static Variables cobus.lombard@gmail.com ASP .Net 1 03-26-2006 11:05 AM
RE: Session Variables assigned to the wrong session? Robert Faulkner ASP .Net 0 01-28-2005 04:16 PM
Session Variables assigned to the wrong session? =?iso-8859-15?Q?Fabr=EDcio_de_Novaes_Kucinskis?= ASP .Net 1 01-20-2005 04:33 PM
Global Session Variables and Session State Earl Teigrob ASP .Net 1 12-17-2003 07:02 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57