Telerik确认的奇怪行为?

时间:2013-08-22 05:43:25

标签: javascript asp.net telerik dopostback telerik-scheduler

SomePage.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>

ClientSideCode.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 ,这是为flag变量设置的默认值 当我进行调试时,我看到客户端点击方法确认被调用,它返回默认值false给控件,点击确认框后取消它再次运行回调方法 confirmCallBackFn(sender)分别返回标志但不在同一个线程但在不同的线程中。我尝试了不同的方法来解决它,但我被卡住了。所以任何帮助都会很棒。

2 个答案:

答案 0 :(得分: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 
    }

答案 1 :(得分: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