0

Html code

<li id="ll" runat="server">
  <a href="#" class="dropdown-toggle" data-toggle="dropdown" >Log In <i class="fa fa-angle-down"></i></a>
  <ul class="dropdown-menu">
    <li><a href="" class ="click" runat="server">Admin</a></li>
    <li><a href="" class ="click" runat="server">Teacher</a></li>
    <li><a href="" class ="click"" runat="server" >Parent</a></li>
   </ul>
 </li> 

javascript file

$('.close').click(function () {
    $('.popup').hide();
    overlay.appendTo(document.body).remove();
    return false;
});

$('.x').click(function () {
    $('.popup').hide();
    overlay.appendTo(document.body).remove();
    return false;
});
$('.click').click(function () {
    overlay.show();
    overlay.appendTo(document.body);
   '<%Session["type"] = "1"; %>'
    $('.popup').show();
    return false;
});

How to set session when clicking <a> ??
I used the code <%Session["type"] = "1"; %> but the session stays Null.

Mr Lister
  • 45,515
  • 15
  • 108
  • 150
Eman Kh
  • 5
  • 4
  • 1
    You cannot access server side Session object from javascript at run time. If you want to set the session from client side you will have to make an ajax call – Nitin Garg Feb 15 '16 at 13:54
  • but i read the example set sesstion in javascript http://stackoverflow.com/questions/15519454/how-can-i-access-session-variables-and-set-them-in-javascript – Eman Kh Feb 15 '16 at 14:07
  • you can copy paste both his setUserName & getUserName function and call those functions next to their definition. You will find that username is being alerted. Now open the view souce of the page you will find that his '%Session line is becoming blank and hence now that function contain only var username and alert. – Nitin Garg Feb 15 '16 at 14:20

1 Answers1

0

asp.net is server side. Javascript is client side.

You can make a javascript file from asp.net (and php, ruby, etc.) and assign values from asp to javascript (var variable = '<%value%>';) But javascript execute himself in client machine, so it do it after asp makes. Javascript can not communicate with asp directly. You must use asynchronous methods like ajax.