Tuesday, September 17, 2013

In asp.net web forms button click event not raised on first click

This happens if you have a textbox with autopostback set to true. I overcame it by moving the code to the page_load event when postback is true. Instead of using a click event.



protected void Page_Load(object sender, System.EventArgs e)
        {
            if (IsPostBack)
            {
                 // put code here
            }
        }
instead of :

    public void ButtonClick(object sender, EventArgs e)
        {
          //...
        }