title: Why won't my LinkButton inside a GridView raise its OnClick event?
body: <p>I have a LinkButton inside a GridView (via an TemplateField).  No matter what I try, the LinkButton will not invoke its event handler.  I have tried both:</p>
  
  <ol>
  <li>A traditional event handler ("OnClick")</li>
  <li>A OnRowCommand event handler at the GridView level.</li>
  </ol>
  
  <p>In both cases, I've debugged and it doesn't even catch the event handler.</p>
  
  <p>If I move the LinkButton out on the page (so it's not in the GridView), it works fine, so I know the syntax is right.</p>
  
  <p>Here is the "traditional" method:</p>
  
  <pre><code>&lt;asp:TemplateField&gt;
    &lt;ItemTemplate&gt;
      &lt;asp:LinkButton Text="Cancel" ID="DeleteButton" CausesValidation="false" OnClick="CancelThis" runat="server" /&gt;
    &lt;/ItemTemplate&gt;
  &lt;asp:TemplateField&gt;
  </code></pre>
  
  <p>What's interesting is if I remove the "CancelThis" method from the code behind, it throws an error.  So I know it's aware of its event handler, because it looks for it when it compiles.</p>
  
  <p>Here is the RowCommand method:</p>
  
  <pre><code>&lt;asp:TemplateField&gt;
    &lt;ItemTemplate&gt;
      &lt;asp:LinkButton Text="Cancel" ID="DeleteButton" CausesValidation="false" CommandName="CancelThis" runat="server" /&gt;
    &lt;/ItemTemplate&gt;
  &lt;asp:TemplateField&gt;
  </code></pre>
  
  <p>In this case, the GridView has:</p>
  
  <pre><code>OnRowCommand="GridView_RowCommand"
  </code></pre>
  
  <p>It postsback, but never <em>hints</em> at raising the event.</p>
  
  <p>Any idea what I'm missing here?</p>