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.



<%@ 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" "">
<html xmlns="">
<head id="Head1" runat="server">
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" >
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                        <telerik:AjaxUpdatedControl ControlID="Label1" />
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
        <br />
        <asp:Button ID="Button2" runat="server" Text="Button"  />
        <br />
        <asp:Label ID="Label1" runat="server" Text=""></asp:Label>
<script type="text/javascript">
    function callConfirm() {
        radconfirm('Are you sure?', confirmCallBackFn);
    function confirmCallBackFn(arg) {
        var ajaxManager = $find("<%=RadAjaxManager1.ClientID%>");
        if (arg) {
        else {

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"
            Label1.Text = "Cancel"
        End If
    End Sub
End Class