I can not use Session In Page_Load and I got error bellow

Posted by LostLord on Stack Overflow See other posts from Stack Overflow or by LostLord
Published on 2010-04-05T08:18:35Z Indexed on 2010/04/05 10:23 UTC
Read the original article Hit count: 273

hi my dear friends ....

why i got this error :

Object reference not set to an instance of an object.

when i put this code in my page_load.:

protected void Page_Load(object sender, EventArgs e)
{
     BackEndUtils.OverallLoader();

     string Teststr = Session["Co_ID"].ToString();
}

==========================================================================

this session is made when user logins to my web site and this session works in other areas...

thanks for your attention

==========================================================================

thanks for your answers

i removed BackEndUtils.OverallLoader(); but error still exists

i tried Teststr = Convert.ToString(Session["Co_ID"]); and error disappeared - but i don't know why that session is null

in other areas that session works perfectly = such as a button in that form

what is the matter?

my web page markup is like this :

<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/AdminBackend.Master" AutoEventWireup="true" CodeBehind="Personel.aspx.cs" Inherits="Darman.Admin.Personel" Theme="DefaultTheme" %>

=================================================================================

i put this code in a button like this :

string Teststr = Convert.ToString(Session["Co_ID"]);

when i press that button THIS code in page Load(POSTBACK) + IN Button_Click works perfectly and shows me 23 (my Co_ID)

But when i run my page in browser (first time) this code in page load shows me null.

why?

thanks a lot

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about c#