Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q2 2011 released 07/12/2011
select

Button / Confirm Postback


  • RadButtons above post the page back to the server, only after the user has confirmed the postback.

    • The first button uses the browser's confirm dialog.
    • The second one uses radconfirm for the confirmation dialog.
    • The last one uses RadWindow to fully customize the look of the dialog.

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="C#" AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="Telerik.Web.Examples.Button.Confirm.DefaultCS" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <qsf:HeadTag ID="Headtag1" runat="server" />
        <style type="text/css">
        .RadWindow_Black
        {
            color:White;
        }
        </style>
    </head>
    <body class="BODY">
        <form id="form1" runat="server">
        <qsf:Header ID="Header1" runat="server" NavigationLanguage="c#" />
        <telerik:RadScriptManager ID="ScriptManager1" runat="server" />
        <script type="text/javascript">
            //<![CDATA[

            //Standard Window.confirm
            function StandardConfirm(sender, args)
            {
                args.set_cancel(!window.confirm("Are you sure you want to submit the page?"));
            }

            //RadConfirm
            function RadConfirm(sender, args)
            {
                var callBackFunction = Function.createDelegate(sender, function (shouldSubmit)
                {
                    if (shouldSubmit)
                    {
                        this.click();
                    }
                });

                var text = "Are you sure you want to submit the page?";
                radconfirm(text, callBackFunction, 300, 100, null, "RadConfirm");
                args.set_cancel(true);
            }

            //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("<%=btnCustomRadWindowConfirm.ClientID %>").click();
                }
            }
            //]]>
        </script>
        <div style="height: 50px">
            <telerik:RadButton ID="btnStandardConfirm" runat="server" Text="Standard window.confirm"
                OnClientClicking="StandardConfirm" OnClick="Button_Click">
            </telerik:RadButton>
            <asp:Label ID="Label1" runat="server" EnableViewState="false" ForeColor="Green" />
        </div>
        <div style="height: 50px">
            <telerik:RadButton ID="btnRadConfirm" runat="server" Text="RadConfirm" OnClientClicking="RadConfirm"
                OnClick="Button_Click">
            </telerik:RadButton>
            <asp:Label ID="Label2" runat="server" EnableViewState="false" ForeColor="Green" />
            <telerik:RadWindowManager ID="windowManager1" runat="server">
            </telerik:RadWindowManager>
        </div>
        <div>
            <telerik:RadButton ID="btnCustomRadWindowConfirm" runat="server" Text="Custom RadWindow Confirm"
                OnClientClicking="CustomRadWindowConfirm" OnClick="Button_Click">
            </telerik:RadButton>
            <asp:Label ID="Label3" runat="server" EnableViewState="false" ForeColor="Green" />
            <telerik:RadWindow ID="confirmWindow" runat="server" VisibleTitlebar="false" VisibleStatusbar="false"
                Modal="true" Behaviors="None" Height="150px" Width="300px">
                <ContentTemplate>
                    <div style="margin-top: 30px; float: left;">
                        <div style="width: 60px; padding-left: 15px; float: left;">
                            <img src="img/ModalDialogAlert.gif" alt="Confirm Page" />
                        </div>
                        <div style="width: 200px; float: left;">
    <asp:Label ID="lblConfirm" Font-Size="14px" Text="Are you sure you want to submit the page?"
    runat="server" />

                            <br />
                            <br />
                            <telerik:RadButton ID="btnYes" runat="server" Text="Yes" AutoPostBack="false" OnClientClicked="YesOrNoClicked">
                                <Icon PrimaryIconCssClass="rbOk" />
                            </telerik:RadButton>
                            <telerik:RadButton ID="btnNo" runat="server" Text="No" AutoPostBack="false" OnClientClicked="YesOrNoClicked">
                                <Icon PrimaryIconCssClass="rbCancel" />
                            </telerik:RadButton>
                        </div>
                    </div>
                </ContentTemplate>
            </telerik:RadWindow>
        </div>
        <qsf:Footer runat="server" ID="Footer1" />
        </form>
    </body>
    </html>

Get more than expected!

 
 

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2024 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451