Assigning value to session in javascript in c# code behind.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Palvids
    New Member
    • May 2009
    • 1

    Assigning value to session in javascript in c# code behind.

    Hi,
    I want to assign some value to session variable in JavaScript written in c# code behind.I hv written like this:
    Code:
    string map2 ="<script language='javascript'>"<%Session["lat"]=varname;%>"; </script>";
    this.RegisterStartupScript("load", map2);
    But it is nt working.
    Please give me solution.

    Thank u.
    Last edited by acoder; Jun 10 '09, 01:09 PM. Reason: Added [code] tags
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    This has now been the rounds so I'm hoping this may find some help in ASP.NET.

    Good luck.

    Comment

    • Bassem
      Contributor
      • Dec 2008
      • 344

      #3
      Do you want to set a session key/value pair when a JavaScript event fires?
      I made up a bad technique but it works.
      I request another page using JavaScript like this:
      Code:
          var url="CommPage.aspx";
          url=url+"?way=receive";
              
          xmlHttpReceiver.onreadystatechange=receiverStateChanged;
          xmlHttpReceiver.open("GET",url,true);
          xmlHttpReceiver.send(null);
      In CommPage.aspx Page_Load do whatever you want.
      You can pass any parameters with their values to be set in session.

      There is no reloading, no redirect occurs.
      I hope it will help.

      Comment

      Working...