1

一些页面.aspx

<asp:LinkButton Runat="server" ID="butDelete" CommandName="Delete" OnClientClick="Confirmation();return flag;"><img src="images/delete.gif" border="0" title='<asp:Literal runat="server" Text="<%$ Resources:ClarityResources, resDelete %>" />'></asp:LinkButton>

客户端代码.js

 function confirmCallBackFn(sender) {
             debugger;
             if (sender)
                 flag = true;
             else
                 flag = false;
             return flag;
         }
         function Confirmation(sender,args) {
             debugger;
             radconfirm('Are you sure you want to delete this file?',  confirmCallBackFn);
         }

但是单击时总是返回false,这是为标志变量设置的默认值当我进行调试时,我看到客户端单击方法确认被调用,它将默认值false返回给控件,然后单击确认框取消它再次单独运行回调方法confirmCallBackFn(sender),该方法返回标志但不在同一个线程中而是在不同的线程中。我尝试了不同的方法来解决它,但我被卡住了。所以任何帮助都会很棒。

4

2 回答 2

2

这就是我提醒用户确认删除事件的方式!

 <telerik:RadButton ID="btnDelete" runat="server" Text="Delete"
  OnClick="btnDelete_clicked" OnClientClicking="RadConfirm" Width="100px">
    </telerik:RadButton>

 <script type="text/javascript">
    function RadConfirm(sender, args) {
        var callBackFunction = Function.createDelegate(sender, function (shouldSubmit) {
            if (shouldSubmit) {
                this.click();
            }
        });
        var text = "Are you sure you want delete ?";
        radconfirm(text, callBackFunction, 300, 100, null, "Confirm Apply !");
        args.set_cancel(true);
    }
</script>

     protected void btnDelete_clicked(object sender, EventArgs e)
    {
       //Write your server-side delete code here 
    }
于 2013-08-23T05:27:23.360 回答
1

您试图以与普通 javascript confirm() 相同的方式处理 radconfirm,这不是以类似的方式完成的。我将从确认功能开始。

function Confirmation(sender, args) {
    debugger;
    // The line below will open a rad confirmation window, it will not wait for the response
    radconfirm('Are you sure you want to delete this file?', confirmCallBackFn);
}

为确保它不会自动回发,应将上述功能更改如下:

function Confirmation(sender, args) {
    debugger;
    // This line will open a rad confirmation window, it will not wait for the response
    radconfirm('Are you sure you want to delete this file?', confirmCallBackFn);
    // The line below will prevent the control from automatically posting back
    return false;
}

下一步是修正回调函数;从代码中可以看出,传递给函数的参数而不是参数名称是确认框结果的布尔表示。

function confirmCallBackFn(sender) {
    debugger;
    if (sender)
        flag = true;
    else
        flag = false;
    return flag;
}

之前编写的函数返回一个值,但这并没有在任何地方使用。以下代码将执行所需的操作

function confirmCallBackFn(arg) {
    debugger;
    if (arg) {
        // The line below will perform a post back, you might want to trigger this a different way
        __doPostBack(sender.id, "");
    }
}

不幸的是,由于发送者没有传递给回调函数,因此有必要在其他 JavaScript 函数中声明该函数,如下所示:

function Confirmation(sender) {
    debugger;
    // The callback function
    function confirmCallBackFn(arg) {
        debugger;
        if (arg) {
            // Triggers postback only when confirmation box returns true
            __doPostBack(sender.id, "");
        }
    }
    // This line will open a rad confirmation window, it will not wait for the response
    radconfirm('Are you sure you want to delete this file?', confirmCallBackFn);
    return false;
}

您可能会发现以下链接对于以与确认相同的方式使用 radconfirm 很有用:

http://demos.telerik.com/aspnet-ajax/window/examples/confirmserverclicks/defaultcs.aspx

于 2013-08-22T13:10:36.360 回答