Access session variables in javascript

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

  1. indkids


    Feb 22, 2012
    Likes Received:
    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()
    "<script type=""text/javascript""> function confirmExit() {")
    " var a; a='<%= Session(""DetailsModified"") %>'; if (a == ""True"")")
    " return ""Recalculate"" } </")
    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.

    indkids, Feb 22, 2012
    1. Advertisements

Ask a Question

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
There are no similar threads yet.