Initializing a value through a Session variable

Posted by William Calleja on Stack Overflow See other posts from Stack Overflow or by William Calleja
Published on 2010-05-05T10:15:33Z Indexed on 2010/05/05 10:18 UTC
Read the original article Hit count: 231

Filed under:
|
|
|

I need to Initialize a value in a Javascript by using a c# literal that makes reference to a Session Variable. I am using the following code

<script type="text/javascript" language="javascript" > 
    var myIndex = <%= !((Session["myIndex"]).Equals(null)||(Session["myIndex"]).Equals("")) ? Session["backgroundIndex"] : "1" %>;

However the code above is giving me a classic Object reference not set to an instance of an object. error. Why? Shouldn't (Session["myIndex"]).Equals(null) capture this particular error?

© Stack Overflow or respective owner

Related posts about c#

Related posts about JavaScript