如何从 GridView 内的 ImageButton 打开 jQuery 对话框?
如何获取 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>
任何帮助将不胜感激。
How can I get the ImageButton ID so that I can use it to open the jquery dialog?
By hard-typing the ImageButton ID, it works as expected. i.e:
$('#ContentPlaceHolder1_GridView1_linkPasswordEdit_0').click(function () {
$('#dialog-modal2').dialog('open');
return false;
});
However, I want to do this with all the ImageButton in the GridView and not only the first one. I have tried various ways like:
$('#ContentPlaceHolder1_GridView1_' + '<%# linkPasswordEdit.ClientID %>').click(function () {
$('#dialog-modal2').dialog('open');
return false;
});
Or:
$('#' + '<%# ContentPlaceHolder1.GridView1.((GridViewRow)Container).FindControl("linkPasswordEdit").ClientID %>').click(function () {
$('#dialog-modal2').dialog('open');
return false;
});
This is what the ImageButton looks like:
<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>
Any help would be greatly appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
为什么不直接将自定义 CSS 类(除了查找图像按钮之外什么也不用)分配给图像按钮并使用 JQuery 类选择器进行关联。
Why not just assign a custom CSS class (used for nothing but finding the image buttons) to the imagebutton and use the JQuery class selector to make the association.