Button click event handler fired on page refresh

Total Post:183

Points:1285
 1110  View(s)
Ratings:
Rate this:

I have an asp.net control, which seems to fire the button click event handler on a page refresh. Why does this happen and how could I avoid it?

  1. Post:378

    Points:2694
    Re: Button click event handler fired on page refresh

    Hi Ankita, 

    try this:

    protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
                Session["update"] =Server.UrlEncode(System.DateTime.Now.ToString());
        }
        protected override void OnPreRender(EventArgs e)
        {
            ViewState["update"] = Session["update"];
        }
        protected void btnProceed_Click(object sender, EventArgs e)
        {          
            if(Session["update"].ToString() ==ViewState["update"].ToString())
                DisplayInfo();
        }
        private void DisplayInfo()
        {
            // Do what ever thing you want to do
            Session["update"] =Server.UrlEncode(System.DateTime.Now.ToString()); 
        }

      Modified On Apr-05-2018 03:43:58 AM

Answer