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?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
  1. Earl Teigrob

    Global Session Variables and Session State

    Earl Teigrob, Dec 16, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    5,004
    Alvin Bruney
    Dec 17, 2003
  2. Jeff Smythe
    Replies:
    3
    Views:
    1,687
    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:
    891
    Alvin Bruney [MVP]
    Jan 20, 2005
  4. Michael
    Replies:
    3
    Views:
    1,364
    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,187
    cobus.lombard@gmail.com
    Mar 26, 2006
  6. =?Utf-8?B?Um9iSEs=?=
    Replies:
    4
    Views:
    6,000
    =?Utf-8?B?Um9iSEs=?=
    Apr 11, 2007
  7. tjumail@gmail.com
    Replies:
    9
    Views:
    1,393
    tjumail@gmail.com
    Mar 23, 2008
  8. Jazzis
    Replies:
    2
    Views:
    478
    Jazzis
    Sep 23, 2003
Loading...