I have this code
if (PreviousPage.IsPostBack)
{
if (Request.Form["username"] == ConfigurationManager.AppSettings["username"] && Request.Form["password"] == ConfigurationManager.AppSettings["password"])
{
Session["username"] = Request.Form["username"];
using (var context = new mallEntities())
{
var countProducts = (from p in context.Products
select p).Count();
var countStores = (from p in context.Stores
select p).Count();
var countCategories = (from p in context.Categories
select p).Count();
Label3.Text = countProducts.ToString();
Label2.Text = countStores.ToString();
Label1.Text = countCategories.ToString();
}
}
else
{
Response.Redirect("Default.aspx?invaild=true");
}
} else if(Session["username"] == null)
{
Response.Redirect("Default.aspx?session=false");
}
and I got this error message:
Object reference not set to an instance of an object
at PreviousPage.IsPostBack
Why?
What is the problem?
I’m not sure why you’re using
PreviousPage.IsPosbackso I’ll guess this is a mistake. You should usePage.IsPostbackIn case you indeed want to use
PreviousPage(I would be stumped) take into account that it can be null if you access the page direclty.