title: jQuery & ASP.NET - Bind $.click() to gridview.Template control
body: <p>I have a Gridview with a template for this Hyperlink:</p>
  
  <pre><code>        &lt;asp:TemplateField HeaderText="Notes" ItemStyle-CssClass="NoMargin NoPadding" SortExpression="lineNotes"&gt;
              &lt;ItemTemplate&gt;
                  &lt;asp:HyperLink id="notesHl" runat="server" text='&lt;%# Bind("lineNotes") %&gt;' Font-Underline="true" Font-Bold="true"&gt;&lt;/asp:HyperLink&gt;
              &lt;/ItemTemplate&gt;
              &lt;ItemStyle Font-Size="Smaller" Height="10px" Width="10px" Wrap="True" /&gt;
          &lt;/asp:TemplateField&gt;
  </code></pre>
  
  <p>Then jQuery that creates a Modal dialogue called by Popup();</p>
  
  <pre><code>    $(document).ready(function () {
          // increase the default animation speed to exaggerate the effect
          $.fx.speeds._default = 1000;
          $(function () {
              $("#divLineItemComments").dialog({
                  autoOpen: false,
                  show: "blind",
                  hide: "explode",
              width: 900,
              height: 500
              });
          });
  
          $("#_ctl0_ContentPlaceHolder1_cwgPhysical__ctl3_notesHl").click(function () {
              $("#divLineItemComments").dialog("open");
              return false;
          });
      });
  
      function Popup() {
          $("#divLineItemComments").dialog("open");
          return false;                       
      }
  </code></pre>
  
  <p>For testing, I hard coded the generated name of the first link in the gridview:</p>
  
  <p><strong>_ctl0_ContentPlaceHolder1_cwgPhysical__ctl3_notesHl</strong></p>
  
  <p>Because ASP.NET generates the id's dynamically, <em>I need to dynamically bind the click event of the hyperlinks.</em>  So that it works with the naming used by ASP.NET.  I could hardcode up to XX generated names (and hope they always generate the same names).  This seems to be a terrible solution...</p>
  
  <p>How can I get the jQuery to bind my Clicks to my Hyperlinks?</p>
  
  <p>Hooking into the rowbound may work, but I don't know how to bind jQuery here</p>
  
  <pre><code>protected void cwgPhysical_RowDataBound(object sender, GridViewRowEventArgs e)
  {
    Hyperlink.NavigateUrl = "javascript:Popup();";//this might work somehow...
  }
  </code></pre>