Hi All,
I am using VS 2005 to build this page.
One the code file I use this code
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class one : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["FirstLoadTime"] == null)
{
Session["FirstLoadTime"] = DateTime.Now.ToString("T");
}
Label1.Text = "Page first loaded at " +
Session["FirstLoadTime"].ToString();
if (IsPostBack)
{
Label1.Text += "<br> Welcome back, "
+ Session["UserName"].ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (Session["UserName"] == null)
{
Session["UserName"] = TextBox1.Text;
}
}
}
But why I always get this error though I have type something in the textbox1
Server Error in '/WebData' Application.
--------------------------------------------------------------------------------
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set
to an instance of an object.
Source Error:
Line 22: if (IsPostBack)
Line 23: {
Line 24: Label1.Text += "<br> Welcome back, "
Line 25: + Session["UserName"].ToString();
Line 26: }