TelerikDeveloper.com

TelerikDeveloper.com

AbrahamA 7/6/2012 8:34:42 PM

Telerik - RadConfirm - How to execute server side code when the dialog closes

This is something that I've strugged with for a while, I'm glad to have found a solution.

When you use the Telerik RadConfirm dialog, it pops up and when it closes it executes Javascript. But I most always need it to execute .NET code in the code behind.

This example shows how to do just that.

 



ASP.NET

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="WebApplication1.WebForm1" %>
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<html xmlns="http://www.w3.org/1999/xhtml">
 
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
 
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" >
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="Label1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
 
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
        </telerik:RadWindowManager>
        <br />
        <asp:Button ID="Button2" runat="server" Text="Button"  />
        <br />
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
    </div>
    </form>
 
</body>
</html>
 
<script type="text/javascript">
    function callConfirm() {
        radconfirm('Are you sure?', confirmCallBackFn);
    }
    function confirmCallBackFn(arg) {
        var ajaxManager = $find("<%=RadAjaxManager1.ClientID%>");
        if (arg) {
            ajaxManager.ajaxRequest('ok');
        }
        else {
            ajaxManager.ajaxRequest('cancel');
        }
    }
</script>

Code Behind

Public Class WebForm1
    Inherits System.Web.UI.Page
 
    Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgsHandles Me.Load
 
    End Sub
 
    Private Sub Button2_Click(sender As Object, e As System.EventArgsHandles Button2.Click
        Dim radalertscript As String = "<script language='javascript'>function f(){callConfirm(); Sys.Application.remove_load(f);}; Sys.Application.add_load(f);</script>"
        Page.ClientScript.RegisterStartupScript(Me.GetType(), "radalert", radalertscript)
    End Sub
 
    Private Sub RadAjaxManager1_AjaxRequest(sender As Object, e As Telerik.Web.UI.AjaxRequestEventArgsHandles RadAjaxManager1.AjaxRequest
        If e.Argument.ToString() = "ok" Then
            Label1.Text = "OK"
        Else
            Label1.Text = "Cancel"
        End If
 
 
    End Sub
End Class