如何获取ImageButton ID以便我可以使用它来打开jquery对话框?
通过硬键入ImageButton ID,它可以按预期工作。即:
$('#ContentPlaceHolder1_GridView1_linkPasswordEdit_0').click(function () {
$('#dialog-modal2').dialog('open');
return false;
});
但是,我想对GridView中的所有ImageButton执行此操作,而不仅仅是第一个。我尝试过各种方式:
$('#ContentPlaceHolder1_GridView1_' + '<%# linkPasswordEdit.ClientID %>').click(function () {
$('#dialog-modal2').dialog('open');
return false;
});
或者:
$('#' + '<%# ContentPlaceHolder1.GridView1.((GridViewRow)Container).FindControl("linkPasswordEdit").ClientID %>').click(function () {
$('#dialog-modal2').dialog('open');
return false;
});
这就是ImageButton的样子:
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:ImageButton ID="linkPasswordEdit" runat="server" CausesValidation="false" OnCommand="passwordEditCommand"
CommandArgument='<%#Eval("id")%>' ToolTip="Click to edit password" ImageUrl="~/Images/imagesActions/password_edit.png"
AlternateText='<%#Eval("userName")%>' />
</ItemTemplate>
</asp:TemplateField>
非常感谢任何帮助。
答案 0 :(得分:4)
为什么不直接将自定义CSS类(仅用于查找图像按钮)分配给图像按钮,并使用JQuery类选择器进行关联。
$('.imageButtonFinderClass').click(function () {
$('#dialog-modal2').dialog('open');
return false;
});
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:ImageButton ID="linkPasswordEdit" runat="server" CausesValidation="false" OnCommand="passwordEditCommand" CssClass="imageButtonFinderClass"
CommandArgument='<%#Eval("id")%>' ToolTip="Click to edit password" ImageUrl="~/Images/imagesActions/password_edit.png"
AlternateText='<%#Eval("userName")%>' />
</ItemTemplate>
</asp:TemplateField>