title: Difference in OnClick for ImageButton inside a GridView vs. regular ImageButton
body: <p>I'm working on a ASP.NET/C# project, and have a GridView control. One of the columns is a TemplateField/ItemTemplate with an ImageButton inside. During the OnClick event, I make a panel visible. When doing this with a regular ImageButton, the page reloads and the panel is visible. This doesn't happen with my ImageButton inside of the GridView. Does anyone know how I can make it do so, or why this is the case?</p>
  
  <p>Thanks for your time, please let me know if you have any questions.</p>
  
  <p>Here's the relevant asp definition</p>
  
  <pre><code>&lt;asp:TemplateField ItemStyle-Width="90px"  ItemStyle-VerticalAlign ="Bottom" ItemStyle-HorizontalAlign ="Center" HeaderText="Add Alias"&gt;
                  &lt;HeaderStyle Font-Bold="True" Font-Size="11px" VerticalAlign="Bottom"/&gt;
                      &lt;ItemTemplate&gt;
                          &lt;asp:ImageButton ID ="btnAddAliasHeader" runat="server" ImageUrl="~/img/AddAlias.gif" onclick="btnAddAlias_Click" /&gt;
                   &lt;/ItemTemplate&gt;
                  &lt;/asp:TemplateField&gt;
  </code></pre>
  
  <p>And here's the C# for the OnClick function.</p>
  
  <pre><code>protected void btnAddAlias_Click(object sender, EventArgs e)
  {
      ImageButton btnAddAlias = (ImageButton)sender;
      GridViewRow row = (GridViewRow)btnAddAlias.Parent.Parent;
      int rowIndex = row.RowIndex;
  
      lblSelectedCity.Text = gvResults.Rows[rowIndex].Cells[0].Text;
      lblSelectedCountry.Text = ddlCountry.Text;
      pnlAddAlias.Visible = true;
  
  }
  </code></pre>
  
  <p>I added the OnRowCommand event and made the panel visible there, however it still doesn't show up. I think it may have something to do with postback, because if I then click the button outside of the gridview, on the reload then the panel from the button inside the gridview shows up fine.</p>
  
  <p>Edit: I'm an idiot and left out that all of this is happening in an updatepanel.</p>