Access session variables in javascript

Discussion in 'ASP General' started by indkids, Feb 22, 2012.

  1. indkids

    indkids

    Joined:
    Feb 22, 2012
    Messages:
    1
    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 As String = "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 As New 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)
    End If

    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!
    indkids, Feb 22, 2012
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Earl Teigrob

    Global Session Variables and Session State

    Earl Teigrob, Dec 16, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    4,272
    Alvin Bruney
    Dec 17, 2003
  2. =?iso-8859-15?Q?Fabr=EDcio_de_Novaes_Kucinskis?=

    Session Variables assigned to the wrong session?

    =?iso-8859-15?Q?Fabr=EDcio_de_Novaes_Kucinskis?=, Jan 20, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    710
    Alvin Bruney [MVP]
    Jan 20, 2005
  3. Robert Faulkner
    Replies:
    0
    Views:
    878
    Robert Faulkner
    Jan 28, 2005
  4. cobus.lombard@gmail.com

    Session Variables and Static Variables

    cobus.lombard@gmail.com, Mar 23, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    934
    cobus.lombard@gmail.com
    Mar 26, 2006
  5. tjumail@gmail.com
    Replies:
    9
    Views:
    945
    tjumail@gmail.com
    Mar 23, 2008
Loading...

Share This Page