2012-03-19 40 views
3

我無法執行確認對話框以要求用戶確認他的刪除選擇。如果用戶單擊取消,則RadButton不應回發到服務器。確認對話框從不顯示,我做錯了什麼?Telerik:防止使用RadButton確認對話框回發

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

回答

5

好吧,我發現了CustomRadWindowConfirmthe telerik website描述的方式。

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