[英]jQuery UI confirmation dialog and asp.net postback
我在gridview中有一个删除按钮。 对于那些不熟悉asp.net的人,我的删除按钮输出如下:
<a id="ctl00_cp1_dtgrAllRates_ctl02_lbDelete"
class="lb"
href="javascript:__doPostBack('ctl00$cp1$dtgrAllRates$ctl02$lbDelete','')">
Delete</a>
我有一个确认对话框,连接到gridview中的所有删除链接,询问用户是否确定要删除。 它弹出没问题,但我想点击回发(href值),如果他们点击确认。 我不知道如何做到这一点,因为对话框代码与单击的链接分开,所以我不能只抓住'this'上的href,例如
var theID = $(this).attr("href");
然后解雇 有没有什么方法可以将href val作为参数传递给对话框代码或某些东西,以便“确认删除”部分在单击按钮时使用它,如果单击“取消”,对话框就会关闭?
这是我的jQuery代码:
$(document).ready(function(){
$("#dialog").dialog({
bgiframe: true,
autoOpen: false,
width: 400,
height: 200,
modal: true,
buttons: {
'Confirm Delete': function() {
$(this).dialog('close');
//fire href here preferably
},
Cancel: function(){
$(this).dialog('close');
}
}
});
$(".lb").click(function(event){
$("#dialog").dialog('open');
event.preventDefault();
});
});
TIA
劳埃德
好的,设法解决它。 我发现这篇文章有点帮助:
但是,帖子中提供的示例并不是很简单,因为对话框的实例化在单击处理程序上是不正确的。 一旦对话框已经实例化,在对话框上设置属性/选项有一种不同的方法。 所以我的最终代码是:
$(document).ready(function(){
$("#dialog").dialog({
modal: true,
bgiframe: true,
width: 500,
height: 200,
autoOpen: false
});
$(".lb").click(function(e) {
e.preventDefault();
var theHREF = $(this).attr("href");
$("#dialog").dialog('option', 'buttons', {
"Confirm" : function() {
window.location.href = theHREF;
},
"Cancel" : function() {
$(this).dialog("close");
}
});
$("#dialog").dialog("open");
});
});
希望这有助于其他人。 Gurdas,谢谢你的帮助,它绝对让齿轮转动。 :)
可能有一种更简洁的方法可以做到这一点,但我认为你必须抓住你点击的链接的上下文,以便在构建对话框时使用它的href; 然后,即使用该参数构造了对话框,也会激活该对话框; 我将更多地考虑一种更有效的方法,但希望这会让一些齿轮转向......
$(".lb").click(function(event){
var theHREF = $(this).attr("href");
$("#dialog").dialog({
bgiframe: true,
autoOpen: false,
width: 400,
height: 200,
modal: true,
buttons: {
'Confirm Delete': function() {
//href fired here
window.location.href= theHREF;
},
Cancel: function(){
$(this).dialog('close');
}
}
}).dialog('open');
很久以前,我已经建立了一个Web控件 ,以标准的集成方式完成。 看一看。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.