Hi All,
I have master page on which I have written a javascript which open ups a new window when user clicks on menu item placed on the left side of master page. The javascript follows
function OpenWind()
{
<% if( HttpContext.Current.Session["Id"]==null) { %>
alert('Session Expired! Redirecting to login page!');
location.href= 'logout.aspx';
<% } %>
var SessionId = <%= HttpContext.Current.Session["Id"].ToString() %>;
window.open('adduser.aspx?Mode=E&&Id='+SessionId+'','AddUser',"resizable,scrollbars,menubar,location,status,toolbar,titlebar,scrollbar");
}and the calling mark up is this
<
a href="#" onclick="javascript:OpenWind();"><asp:Label runat="server" ID="lbl_MyProfile" Text='My Profile'></asp:Label></a>But this fails gives me object reference not set to an instance error when HttpContext.Current.Session["Id"] is null.
![]() |
0 |
![]() |
from where you are assigning HttpContext.Current.Session["Id"].ToString() the value ?
get the values if not null
<% if( HttpContext.Current.Session["Id"] !=null) { %>
var SessionId = <%= HttpContext.Current.Session["Id"].ToString() %>;<% } %>
"Never underestimate the power of stupid people in large groups"
![]() |
0 |
![]() |
Hello
Assign Session variable like this
Session[
"Id"] = Context.Session.LCID;then check as ur condition
<% if( HttpContext.Current.Session["Id"]==null) { %>
alert('Session Expired! Redirecting to login page!');
location.href= 'logout.aspx';
<% } %>
var SessionId = <%= HttpContext.Current.Session["Id"].ToString() %>;
![]() |
0 |
![]() |
You can't call a method on an object that is not null, so you can't perform a (null).ToString(). I always prefer to maximise the amount of logic in the code-behind wherever possible, so I would prefer to put a method in my code-behind to produce the information needed, but if you want to use inline code do something like this (note that I always code in C#, but you might be able to use an inline IF in VB):
var SessionId = <%= (HttpContext.Current.Session["Id"] == null) ? string.Empty : HttpContext.Current.Session["Id"].ToString() %>;
Andrew
blog.andrewrivers.co.uk
![]() |
0 |
![]() |
Thanks All,
And sory for relayed reponse.
the code is changed as
function OpenWind()
{
<% if( HttpContext.Current.Session["Id"]==null) { %>
alert('Session Expired! Redirecting to login page!');
location.href= 'logout.aspx';
<% } else { %>
var SessionId = <%= HttpContext.Current.Session["Id"].ToString() %>;
window.open('adduser.aspx?Mode=E&&Id='+SessionId+'','AddUser',"resizable,scrollbars,menubar,location,status,toolbar,titlebar,scrollbar");
<% } %>}
And Finally Solved. Thanks All.
![]() |
0 |
![]() |