[英]Postback in jQuery UI dialog
I've a gridview with some rows. 我有一些行的gridview。 On each row I have an imagebutton on the right side of the grid that offer the possibility to delete a record.
在每一行中,我在网格的右侧都有一个imagebutton,可以删除记录。
Clicking on the imagebutton is show a dialog created with jQuery UI. 单击图像按钮会显示一个使用jQuery UI创建的对话框。
jQuery code is: jQuery代码是:
$("[name*='btn_check']").click(function() {
event.preventDefault();
$("#dialog-confirm").dialog({
autoOpen: true,
resizable: false,
height: 200,
modal: true,
buttons: {
"Accept": function() {
$(this).dialog("close");
},
Cancel: function() {
$(this).dialog("close");
}
}
});
});
Code is quite simple and common for jQuery UI dialog. 对于jQuery UI对话框,代码非常简单且通用。
So, now I wan to execute code when "Accept" button is clicked and I though __doPostBack
could be a good solution. 因此,现在我想在单击“接受”按钮时执行代码,尽管
__doPostBack
可能是一个很好的解决方案。
So, I've created an hidden button in my gridview (near the imagebutton), then I've added this code to "Accept" function, as I found on another StackOverflow question: 因此,我在gridview中创建了一个隐藏按钮(在imagebutton附近),然后将此代码添加到“ Accept”函数中,正如我在另一个StackOverflow问题上发现的那样:
__doPostBack('btn_hidden', '');
I've also tried to use this: 我也尝试使用此方法:
__doPostBack('<%= btn_hidden.UniqueID %>', '');
But without success. 但是没有成功。
So, which is the right way to execute a postback and how can I send the ID of the record to delete this record with code behind? 因此,哪种方法是执行回发的正确方法,又如何发送记录ID来删除后面带有代码的记录呢?
First of all you should have a correct CommandName
and CommandArgument
set on your ImageButton
. 首先,您应该在
ImageButton
上设置正确的CommandName
和CommandArgument
。 Then call dialog from the OnClientClick
. 然后从
OnClientClick
调用对话框。 As I understood you have only one dialog element hidden somewhere so there should be no problems with ids: 据我了解,您仅在某个位置隐藏了一个对话框元素,因此id应该没有问题:
<asp:ImageButton runat="server"
CommandName="Delete"
CommandArgument='<%# Eval("YourKeyFieldNameHere") %>'
OnCommand="ImageButton_Command"
OnClientClick="javascript:return showConfirmDialog(this.name)"
/>
function showConfirmDialog(uniqueId) {
$("#dialog-confirm").dialog({
autoOpen: true,
resizable: false,
height: 200,
modal: true,
buttons: {
"Accept": function() {
$(this).dialog("close");
__doPostBack(uniqueId, '');
},
Cancel: function() {
$(this).dialog("close");
}
}
});
return false; // this is to prevent default click handler to cause a postback
}
Codebehind: 代码隐藏:
protected void ImageButton_Command(object sender, CommandEventArgs e)
{
// e.CommandArgument will contain the record key and
// e.CommandName will be equal to "Delete" or whatever you'll set on aspx
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.