BUTTON CLICK EVENT HANDLER FIRED ON PAGE REFRESH

Ankita Pandey

Total Post:183

Points:1285
Posted by  Ankita Pandey
 917  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. Sumit Kesarwani

    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()); 

        }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!