Click here to Skip to main content
15,887,676 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Line 17:     {
Line 18:         //checks if user is login or not
Line 19:         if (Session["islogin"].ToString() == "false")
Line 20:         {
Line 21:             Response.Redirect("LoginPage.aspx");

Source File: c:\Users\INTIME\Desktop\New folder\Web Application Project\Project-Online Travel Agency\Billing.aspx.cs    Line: 19 

Stack Trace: 


[NullReferenceException: Object reference not set to an instance of an object.]
   OfflinePayment.Page_Load(Object sender, EventArgs e) in c:\Users\INTIME\Desktop\New folder\Web Application Project\Project-Online Travel Agency\Billing.aspx.cs:19
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Control.LoadRecursive() +50
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627


in the code

C#
public partial class OfflinePayment : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //checks if user is login or not
        if (Session["islogin"].ToString() == "false") //LINE-19
        {
            Response.Redirect("LoginPage.aspx");
        }
        LblDateError.Visible = false;
        Lblservice.Text = Session["service"].ToString().ToUpper();
        Lblservice1.Text = Session["service"].ToString();
        Lblserviceid.Text = Session["serviceId"].ToString();
        Lbldate.Text = DateTime.Now.ToString();
        LblCostPerson.Text = Session["cost_per_person"].ToString();
        Lblcust.Text = Session["custId"].ToString();
    }


please help me solve this problem.
Posted
Updated 3-Dec-12 19:18pm
v2
Comments
Programm3r 4-Dec-12 1:06am    
Hi - Well it would seem that you have a NullReferenceException at line #19. So put a breakpoint at line #19 and check which variable is null.

My guess is, that one of the Session indexes doesn't exist, and by calling ToString() on it causes the NullReferenceException

Hi,

Update your code as below.

C#
public partial class OfflinePayment : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //checks if user is login or not
        if(Session["islogin"] == null ||  Session["islogin"].ToString() == "false")
             Response.Redirect("LoginPage.aspx");

        LblDateError.Visible = false;
        Lblservice.Text = Session["service"].ToString().ToUpper();
        Lblservice1.Text = Session["service"].ToString();
        Lblserviceid.Text = Session["serviceId"].ToString();
        Lbldate.Text = DateTime.Now.ToString();
        LblCostPerson.Text = Session["cost_per_person"].ToString();
        Lblcust.Text = Session["custId"].ToString();
}

This may help you.
 
Share this answer
 
v2
problem is,
Session["islogin"].ToString()


your session named "isLogin" is not created so gives null value,
so,
Session["islogin"] = Null
and in this case run time statement is,
Null.ToString()

and Null are not coverted in string (they haven't this method you are accessing)

so, please make sure that "islogin" session is created and after that you can use it,

else put condition,

C#
if (session["islogin"] != Null)
{
   if (Session["islogin"].ToString() == "false") 
   {
     ....
   }
}


Happy Coding!
:)
 
Share this answer
 

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



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