Home > DeveloperSection > Forums > Button click event handler fired on page refresh
Ankita Pandey
Ankita Pandey

Total Post:183

Points:1285
Posted on    August-22-2014 1:32 AM

 ASP.Net ASP.Net 
Ratings:


 1 Reply(s)
 646  View(s)
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?



Sumit Kesarwani

Total Post:378

Points:2694
Posted on    August-22-2014 2:02 AM

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

    }


Don't want to miss updates? Please click the below button!

Follow MindStick