title: ASP.NET GridView SelectedIndexChanged not fired on async postback
body: <p>I have seen a lot of forum topics on this issue; but none seem to fix it in my case. I have a GridView inside an Update Panel, which fires asynchronous postback on row click - this part is working. During the asynchronous postback though, the SelectedIndexChanged event handler is never called even though the postback passes through the Page_Load, RowDataBound, etc - pretty much all event handlers except the SelectedIndexChanged. </p>
  
  <p><b>Kindly refer to my makrup below:</b></p>
  
  <pre><code>&lt;asp:UpdatePanel ID="Panel" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="True"&gt;
      &lt;ContentTemplate&gt;
          &lt;asp:GridView ID="GridView" runat="server" AllowSorting="True" OnRowDataBound="OnRowDataBound" OnSorting="OnSorting" AutoGenerateColumns="True" OnSelectedIndexChanged="OnSelectedIndexChanged" &gt;&lt;/asp:GridView&gt;
      &lt;/ContentTemplate&gt;
      &lt;Triggers&gt;
          &lt;asp:AsyncPostBackTrigger ControlID="outsideControl1" EventName="Click" /&gt;
          &lt;asp:AsyncPostBackTrigger ControlID="outsideControl2" EventName="Click" /&gt;
      &lt;/Triggers&gt;
  &lt;/asp:UpdatePanel&gt;
  </code></pre>
  
  <p><b>And the code behind:</b></p>
  
  <pre><code>protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
  {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
      e.Row.Attributes["onclick"] = Page.ClientScript.GetPostBackClientHyperlink(Panel, "Select$" + e.Row.RowIndex);
    }
  }
  
  protected void OnSelectedIndexChanged(object sender, EventArgs e)
  {
      // ** Do stuff here **
  }
  </code></pre>
  
  <p>I can see that the attribute "onclick" is added as the GridView does fire asynchronous postbacks whenever any of the rows is clicked. The problem is that the event handler OnSelectedIndexChanged is never called. I'm running out of ideas as to why a partial postback is made; but the event that caused it is not recognized.</p>
  
  <p><b>Here are some solutions I've tried, but obviously did not work:</b></p>
  
  <p>1.) Added the GridView as an Async Postback Trigger:</p>
  
  <pre><code>&lt;asp:AsyncPostBackTrigger ControlID="GridView" EventName="SelectedIndexChanged" /&gt;
  </code></pre>
  
  <p>Since I have ChildrenAsTriggers="True", I knew this was unnecessary but I had to try anyway.</p>
  
  <p>2.) Added the GridView as a full Postback Trigger: </p>
  
  <pre><code>&lt;asp:PostBackTrigger ControlID="GridView" EventName="SelectedIndexChanged" /&gt;
  </code></pre>
  
  <p>Still did not work, and I don't want this behavior anyway.</p>
  
  <p>3.) Changed the attribute statement in row data bound as follows:</p>
  
  <pre><code>e.Row.Attributes["onclick"] = "__doPostBack('" + this.UniqueID + "$" + GridView.ID + "', 'Select$" + e.Row.RowIndex + "')";
  </code></pre>
  
  <p>This made a full postback instead of partial, and SelectedIndexChanged is still not called anyway.</p>
  
  <p>4.) Tried to change the event from SelectedIndexChanged, to SelectedIndexChanging, or even RowCommand (as long as I can capture the calling Row)... but neither of them is called.</p>
  
  <p>Please take note that this works perfectly for full postback if the GridView is not in the Update Panel. Unfortuantely, I need the postback to be asynchronous.</p>
  
  <p>If anyone has ideas on what is happening, it will be greatly appreciated if you can share them. Thanks!</p>
  
  <p><b>Note:</b> Having a column with 'Select' buttons is not an acceptable solution (obviously I know this before asking this question). The rows have to be clickable themselves.</p>