Accessing Session Variables in .JS page

950
2
Jump to solution
08-19-2014 01:44 PM
jaykapalczynski
Frequent Contributor

Accessing Session Variables in .JS page

I have my Session variable accessible at the .ASPX page....

But I also have a .JS page that is defining the map and layers to render.

I need to get the session variable in the .JS page....cant figure out how to...

Anyone have any thoughts?

I am trying to get the value of the Hidden Input type in .JS page like this

IN .JS PAGE

var varToken = registry.byId("tokentext");

alert(varToken);

In the .aspx page and .aspx.vb page I can alert the Session variable as such

IN .NET

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load

   tokentext.Value = Session("tokentext")

End Sub

IN .ASPX PAGE

<form id="form1" runat="server">

  <div>

   <asp:Label ID="tlabel" runat="server"></asp:Label>

  <input type="hidden" id="tokentext" name="tokentext" runat="server"/>

  <asp:Button ID="Button1" runat="server" Text="Button" style="margin-left: 55px" />

  </div>

  <script type="text/javascript">

        var tvalue = document.getElementById('<%= tokentext.ClientID%>').value

        alert(tvalue);

  </script>

</form>

0 Kudos
1 Solution

Accepted Solutions
jaykapalczynski
Frequent Contributor

Was able to get the value from the Hidden Input as such

var test = document.getElementById('tokentext').value

alert('Returned Session variable: ' + test);

View solution in original post

0 Kudos
2 Replies
jaykapalczynski
Frequent Contributor

Was able to get the value from the Hidden Input as such

var test = document.getElementById('tokentext').value

alert('Returned Session variable: ' + test);

0 Kudos
jaykapalczynski
Frequent Contributor

Update:

Was then able to parse the return....

This is what the tokentext.value looks like:

{"token":"bgfhf87999999hdhwsu8d.","expires";1408485233476}

var test = document.getElementById('tokentext').value

var JsonParseToken = JSON.parse(test);

var MapServerToken = (JsonParseToken.token);

alert(MapServerToken);

0 Kudos