Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Accessing Session variable from javascript

    Hi,

    I'm making my first ASP.NET web application. I read in several forums that it is possible to access a Session variable from javascript by using the following syntax:

    var a = '<%=Session("Village")%>';

    However, variable 'a' gets the value "<%=Session("Village")%>" instead of the value of Session variable 'Village'.

    Any ideas what I'm doing wrong?

    Thanks in advance!

  • #2
    New Coder
    Join Date
    Mar 2010
    Location
    nyc
    Posts
    31
    Thanks
    0
    Thanked 1 Time in 1 Post
    Make sure that your javaScript code is on a page that is is being processed by .net. It has to end with .aspx.

  • #3
    New to the CF scene
    Join Date
    Aug 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    its correct.
    <script>
    var MyClientSideVar = <%= Session("MySessionVar")%>;
    alert(MyClientSideVar);
    </script>


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •