Write session in VB/C#, read session in Javascript - What is Proper Way?http://forums.asp.net/t/960815.aspx/1?Write+session+in+VB+C+read+session+in+Javascript+What+is+Proper+Way+Wed, 08 Feb 2006 03:11:19 -05009608151191523http://forums.asp.net/p/960815/1191523.aspx/1?Write+session+in+VB+C+read+session+in+Javascript+What+is+Proper+Way+Write session in VB/C#, read session in Javascript - What is Proper Way? <p><font color="#000000">I've got an app that gets some information and stores it into 2 variables, then writes this information to a session variable, all via </font><font color="#000000">VB.&nbsp;</font></p> <p>I then try to retrieve the session variable via Javascript and C#.</p> <p>It works, but it's flakey.&nbsp;&nbsp; 1.) am I doing this correctly?&nbsp; 2.) is there a better way?</p> <p>Here's the code that writes the session variable out:</p> <p><br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Session.Add(&quot;Session1&quot;,&nbsp;it1<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Session.Add(&quot;Session2&quot;, it2)&nbsp; </p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; I also used </p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Session(&quot;SessionKey&quot;) =&nbsp;123</p> <p>Then I read back via JavaScript using...</p> <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; user_id = '&lt;%=Session(&quot;SessionKey&quot;)%&gt;';</p> <p>The problem is although SessionKey comes back ok, reading the others does not when I read back in the same fashion...</p> <p>&nbsp;&nbsp; the_item1 = '&lt;%=Session(&quot;Session1&quot;)%&gt;';</p> <p>&nbsp;&nbsp; the_item2 = '&lt;%=Session(&quot;Session1&quot;)%&gt;';</p> <p>When these lines are added, it messes up the Javascript and makes the lines after it not work properly (some lines execute, some don't).</p> <p>&nbsp;</p> <p>So 2 questions:</p> <p>1.) What is the proper way to handle session variables across VB/C# to Javascript?</p> <p>2.) Someone mentioned that you shouldn't use the OnLoad= in the &lt;body&gt; tag, because it sometimes fires sometimes doesn't or is unreliable in some way.&nbsp; Is that true?&nbsp; If so, what is the proper way to handle onload&nbsp;to&nbsp;exectute a&nbsp;Javascript function on page load.&nbsp; This may account for some of the issues I am seeing.</p> <p>&nbsp;</p> <p>Thank you</p> 2006-02-08T03:11:19-05:00