Access session variables in javascript

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

  1. indkids

    indkids

    Joined:
    Feb 22, 2012
    Messages:
    1
    Likes Received:
    0
    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. Advertisements

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,960
    Alvin Bruney
    Dec 17, 2003
  2. Jeff Smythe
    Replies:
    3
    Views:
    1,559
    Jeff Smythe
    Jan 2, 2004
  3. =?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:
    847
    Alvin Bruney [MVP]
    Jan 20, 2005
  4. Michael
    Replies:
    3
    Views:
    1,312
    Jim Cheshire
    Dec 30, 2005
  5. cobus.lombard@gmail.com

    Session Variables and Static Variables

    cobus.lombard@gmail.com, Mar 23, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,129
    cobus.lombard@gmail.com
    Mar 26, 2006
  6. =?Utf-8?B?Um9iSEs=?=
    Replies:
    4
    Views:
    5,856
    =?Utf-8?B?Um9iSEs=?=
    Apr 11, 2007
  7. tjumail@gmail.com
    Replies:
    9
    Views:
    1,319
    tjumail@gmail.com
    Mar 23, 2008
  8. Jazzis
    Replies:
    2
    Views:
    424
    Jazzis
    Sep 23, 2003
Loading...