Click here to Skip to main content
15,891,762 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i made a dropdown using this

out.println("<select name=\"drplistalbum\" onmousedown=\"this.value='';\" onchange=\"jsFunction(this.value);\">");


and my javascript is

XML
<script type='text/javascript'>
                 function jsFunction(value)
                 {
       //                      alert(value);
                      Session["drpname"] = value;
                 }
                     </script>


but i get an error

Uncaught ReferenceError: Session is not defined
Posted
Comments
Kornfeld Eliyahu Peter 4-Nov-15 7:04am    
Based on your code Session is NOT defined - you only use it, but no definition!!!
Why do you think javascript need no variable declaration?

Session is a Server concept, not a Client: the Session is only available within the C# or VB code that runs in the code behind. The Session data is not available in Javascript.

I'd suggest that if you need this kind of function in Javascript, you should look at using cookies instead.
 
Share this answer
 
Comments
Member 9671810 5-Nov-15 3:07am    
setCookie("drpname", value, 365);
alert('drpname');

if i use this, i get error "Uncaught ReferenceError: setCookie is not defined"
OriginalGriff 5-Nov-15 3:55am    
When you randomly grab code from the internet, you are going to have problems.
You can't just skim some code, grab a line and hope it will work: it won't.
setCookie isn't a javascript method, it's one that was defined on the same page you got that very code from:
http://www.w3schools.com/js/js_cookies.asp
So go back there, and read the whole page - then use the appropriate bits rather than assuming that a single line grabbed from the page will do exactly what you want...
XML
 <script type="text/javascript">
function SetUserName()
{
    var userName = "Shekhar Shete";
    '<%Session["UserName"] = "' + userName + '"; %>';
     alert('<%=Session["UserName"] %>');
}
</script>
 
Share this answer
 
Comments
Member 9671810 4-Nov-15 8:40am    
i tried using this also but it gives me error..
Uncaught ReferenceError: jsFunction is not defined

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900