【发布时间】:2014-03-20 20:09:19
【问题描述】:
我是 jQuery 的新手,并尝试按照这篇文章在 Gridview 项目上实现 jQuery UI 对话框: http://www.codeproject.com/Articles/238122/Delete-Functionality-in-GridView-with-Confirmation
我已经使用 Chrome 开发工具逐步完成了这段代码,并且对话框正确显示,但是当我单击删除按钮时,关联的匿名函数 __doPostBack(uniqueID 似乎没有触发。可以设置一个 JS 断点来捕获一个单击客户端上的“删除”按钮?对于服务器端代码,我在 Visual Studio 中有一个断点,通常会输入回发但它从未命中。
这里是我的 ASP.Net Gridview 的相关栏目:
<asp:TemplateField HeaderText="Deleting..">
<ItemTemplate>
<!--To fire the OnRowDeleting event.-->
<asp:LinkButton ID="lbDelete" runat="server" CommandName="Delete"
OnClientClick="return deleteItem(this);"
ControlStyle-CssClass="buttonInRow"
Text="Delete">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
这是它的渲染方式:
<td>
<!--To fire the OnRowDeleting event.-->
<a onclick="return deleteItem(this);" id="ctl00_MainContentPlaceHolder_GridView1_ctl02_lbDelete" class="buttonInRow" href="javascript:__doPostBack('ctl00$MainContentPlaceHolder$GridView1$ctl02$lbDelete','')">Delete</a>
</td>
以下脚本没有错误:
$(function() {
InitializeDeleteConfirmation();
});
function InitializeDeleteConfirmation() {
$('#deleteConfirmationDialog').dialog({
autoOpen: false,
resizable: false,
height: 140,
modal: true,
buttons: {
"Delete": function() {
$(this).dialog("close");
},
Cancel: function() {
$(this).dialog("close");
}
}
});
}
function deleteItem(element) {
var uniqueID = element.id;
var row = element.parentNode.parentNode;
// Cells[n]: n referring to the cell number displayed on GridView; n starting from 0...
var PositionTitle = row.cells[0].innerText;
var dialogTitle = 'Permanently Delete Item: ' + PositionTitle + '?';
$("#deleteConfirmationDialog").html('<p><span class="ui-icon " + "ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>" + "Please click delete to confirm deletion.</p>');
$("#deleteConfirmationDialog").dialog({
title: dialogTitle,
buttons: {
"Delete": function () { __doPostBack(uniqueID, '');
$(this).dialog("close"); },
"Cancel": function () { $(this).dialog("close"); }
}
});
$('#deleteConfirmationDialog').dialog('open');
return false;
}
这里的想法是上面的 deleteItem 脚本总是返回 false 因为(表面上)它在关闭对话框之前处理回发(即与呈现的 HTML 上的代码相同)上面的sn-p)。这个 __doPostBack 函数会不会在我身上失败并且不会中断调试器?
【问题讨论】:
标签: jquery asp.net jquery-ui gridview jquery-ui-dialog