jQuery UI确认对话框和asp.net回发

jQuery UI确认对话框和asp.net回发

问题描述:

我在gridview中有一个删除按钮.对于不熟悉asp.net的用户,我的删除"按钮的输出如下:

I have a delete button in a gridview. For those not familiar with asp.net my delete button outputs like so:

<a id="ctl00_cp1_dtgrAllRates_ctl02_lbDelete" 
   class="lb"
   href="javascript:__doPostBack('ctl00$cp1$dtgrAllRates$ctl02$lbDelete','')">
Delete</a>

我在gridview中的所有删除链接上都有一个确认对话框,询问用户是否确定要删除.它弹出没有问题,但是如果他们单击确认,我想触发回发(href值).我不确定如何执行此操作,因为对话框代码与所单击的链接是分开的,所以我不能只是抓住"this"上的href,例如

I have a confirmation dialog hooked up to all the delete links in the gridview to ask the user if they are sure they want to delete. It pops up no problem but I want to fire the postback (the href value) if they click confirm. I'm not sure how to do this as the dialog code is seperate to the link that is clicked so I can't just grab the href on 'this' e.g.

var theID = $(this).attr("href");

然后开火.有什么方法可以将href val作为参数传递给对话框代码或其他方法,以便单击按钮时单击确认删除"部分,如果单击取消",则对话框关闭?

and fire that. Is there some way I can pass the href val as a parameter to the dialog code or something so that the 'Confirm Delete' section uses it when the button is clicked and if 'Cancel' is clicked the dialog just closes?

这是我的jQuery代码:

Here is my jQuery code:

$(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

劳埃德

好,解决了这个问题.我碰到了这篇文章,对您有所帮助:

Ok, managed to solve it. I came across this post which helped a little:

如何实施确认"对话框在Jquery UI对话框中?

但是,仅因为对话框的实例化在单击处理程序上不正确,导致帖子中提供的示例无法完全发挥作用.实例化对话框后,可以通过另一种方法在对话框上设置属性/选项.所以我的最终代码是:

However the example provided in the post wasn't quite working simply because the instantiation of the dialog was incorrect on the click handler. There is a different way of setting properties/options on the dialog once a dialog has already been instantiated. So my final code was:

$(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),非常感谢您的帮助,它一定能使机器运转. :)

Hope this helps someone else. Gurdas, thanks for your help, it definately got the gears turning. :)