I'm pretty new to jQuery and I'm having problems with picking up button click events in jQuery from buttons generated within an ItemTemplate in an ASP Repeater.
I've spent a few (wasted) hours searching for an answer that will work, with no luck yet.
A snip from My .ASPX page:
<asp:Repeater ID="rptJobs" runat="server">
<ItemTemplate>
<asp:Panel ID="Panel1" runat="server">
<table>
<tr>
<td>Desc:</td>
<td></td>
<td><%#Eval("DESCRIPTION")%></td>
</tr>
</table>
<asp:Button runat="server" ID="myBtn" Tag='<%# Eval("JOB_NO") %>' Text='Go' />
</asp:Panel>
</ItemTemplate>
</asp:Repeater>
The generated HTML:
<div id="rptJobs_ctl00_Panel1">
<table>
<tr>
<td>Desc:</td>
<td></td>
<td>Test Data 1</td>
</tr>
</table>
<input type="submit" name="rptJobs$ctl00$myBtn" value="Go" id="rptJobs_ctl00_myBtn_0" Tag="MI0683" />
</div>
<div id="rptJobs_ctl01_Panel1">
<table>
<tr>
<td>Desc:</td>
<td></td>
<td>Test Data 2</td>
</tr>
</table>
<input type="submit" name="rptJobs$ctl01$myBtn" value="Go" id="rptJobs_ctl01_myBtn_1" Tag="MI0684" />
</div>
Now, this jQuery works (specifying the generated button id):
<script language="javascript" type="text/javascript">
$(document).ready(function () {
$(function () {
$("#rptJobs_ctl00_myBtn_0").click(function () {
// This displays the text from the Tag element of the button...
alert($(this).attr("tag"));
});
});
});
</script>
However, I want to be able to use a generic function that will be called for the click event for all the generated buttons - any help appreciated!
Ted H