Access session variables in javascript


Joined
Feb 22, 2012
Messages
1
Reaction score
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!
 
Ad

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. After that, you can post your question and our members will help you out.

Ask a Question

Top