title: Page_Load executes twice
body: <p>This issue has to with my page loading twice on a post back. I'm not up to par with the page life cycle in asp.net hence my post.</p>
  
  <p>Short searching revealed that AutoEventWireup is a player in this which presently is not referenced in my Page directive. Stepping through the code the Page_Load executes two times, first time from the OnInint/InitializeComponent where the following was auto generated: <code>this.Load += new System.EventHandler(this.Page_Load);</code>. The main issue is this: I have class level variable <code>Int32 totalDuration = 0;</code> that is populated in the gridView RowDataBound event by adding up the values of a cell called "Duration". For example the grid view contains two rows where in the first row the cell contains a value of 35 (minutes) and the second row contains 25. The purpose is to add up all the minutes from each row. Here is the simplified method:</p>
  
  <pre><code>protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
      {
          DataRowView drv = (DataRowView)e.Row.DataItem;
  
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              totalDuration = totalDuration + Convert.ToInt32(drv["Duration"]);
          }
  
          lblMinutes.Text = totalDuration.ToString("#,##0");
      }
  </code></pre>
  
  <p>Because the Page_Load executes twice the value of totalDuration is doubled, which is obviously incorrect. As a fix I commented out the  <code>this.Load += new System.EventHandler(this.Page_Load);</code> in the InitializeComponents method. Site and page seem to work but I am not certain if this really a solution for the underlying issue.</p>
  
  <p>I am open to your suggestions and I would welcome some explanation about the whole InitilalizeComponent or the Autowireup stuff, etc.</p>
  
  <p>Thank you,
  Risho</p>
  
  <p>EDIT: The Page_Load looks like this:</p>
  
  <pre><code>private void Page_Load(object sender, System.EventArgs e)
      {
          if (!Page.IsPostBack)
          {
              /code removed/
  
              bindGrid(site, metric, month, year);
          }
      }
  
  private void bindGrid(string site, string metric, int month, int year)
      {
          /code removed/
          gv.DataSource = dvSearch;
          gv.DataBind();
      }
  </code></pre>