Telerik : preventing postback with RadButton confirm dialog

限于喜欢 提交于 2019-12-10 20:28:05

问题


I am having trouble to implement the confirm dialog to ask the user to confirm his choice to delete. The RadButton should not postback to the server if the user clicks cancel. The confirm dialog never shows, what am I doing wrong?

<script type="text/javascript">
    function confirmAspButton(button) {
        function aspButtonCallbackFn(arg) {
            if (arg) {
                __doPostBack(button.name, "");
            }
        }
        radconfirm("Are you sure you want to delete?", aspButtonCallbackFn, 330, 110, null, "Confirm");
    }
</script>


<telerik:RadButton
    ID="btnDeleteLines" 
    runat="server" 
    OnClientClicking="confirmAspButton(this); return false;"
    OnClick="btnDeleteLines_Click"
    Text="Delete line(s)"
    AutoPostBack="false"
    GroupName="GroupName1">
</telerik:RadButton>

回答1:


Ok, I found out a way described on the telerik website, the CustomRadWindowConfirm.

<script type="text/javascript">
    //Custom RadWindow Confirm
    function CustomRadWindowConfirm(sender, args)
    {
        //Open the window
        $find("<%= confirmWindow.ClientID %>").show();
        //Focus the Yes button
        $find("<%= btnYes.ClientID %>").focus();
        //Cancel the postback
        args.set_cancel(true);
    }
    function YesOrNoClicked(sender, args)
    {
        var oWnd = $find("<%= confirmWindow.ClientID %>");
        oWnd.close();
        if (sender.get_text() == "Yes")
        {
            $find("<%= btnDeleteLines.ClientID %>").click();
        }
    }
</script>


<telerik:RadButton
    ID="btnDeleteLines" 
    runat="server" 
    OnClientClicking="CustomRadWindowConfirm"
    OnClick="btnDeleteLines_Click"
    Text="Delete line(s)"
    AutoPostBack="false"
    GroupName="GroupName1">
</telerik:RadButton>


来源:https://stackoverflow.com/questions/9772670/telerik-preventing-postback-with-radbutton-confirm-dialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!