I have a some the query on the .Net web form application.i have very simple web application which have a one button and label. i am doing some operation on the click event of the button.it's all fine,getting all expected output.but here one problem i am getting is the web page refresh.When i was refreshing the web browser program was starting.so to prevent it i used session method so program not starting after the refresh button but getting Object reference not set to an instance of an object error.
Please have a look on the code side. i am trying to avoid the error but it's behaving the same. when i click the refresh button on the browser i am getting error [NullReferenceException: Object reference not set to an instance of an object.]. this error is generating from the comparison of the both the state in button click function.
might be it's taking time to update the ViewState["CheckRefresh"] state. please suggest some solution for this.or is there any other method stop auto-start program on the web browser refresh.
        protected void Page_Load(object sender, EventArgs e)
        {
              localDirPath = Server.MapPath("~/");
              log.setLogPath(localDirPath);
              localStorePath = localDirPath + "/download/";
              if (!IsPostBack)
              {
                    Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
              }
        }
        protected void Button2_Click(object sender, EventArgs e)
        {
              Label1.Text = "";
              UpdateTimer.Interval = 100;
              if (ViewState["CheckRefresh"] != null && !ViewState["CheckRefresh"].Equals("-1"))
              {
                    if (Session["CheckRefresh"].ToString() == ViewState["CheckRefresh"].ToString())
                    {
                          Session.Remove("JobManager");
                          //start the porcess if button click
                          Session["CheckRefresh"] = Server.UrlDecode(System.DateTime.Now.ToString());
                          UpdateTimer.Enabled = true;
                          Label1.Enabled = true;
                          isbuttonpressed = true;
                    }
                    else
                    {
                          //disable the process if browser the refresh
                          UpdateTimer.Enabled = false;
                          Label1.Enabled = false;
                    }
              }
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
              ViewState["CheckRefresh"] = Session["CheckRefresh"];
        }
