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

Window / Alert, Prompt, Confirm

Browser GUI: Alert, Prompt, Confirm


Dialogs called from client:






 

Dialogs called from server:







The button below defines a custom code in its OnClientClick event that uses radconfirm to mimic the blocking of the execution thread.
The approach has the following limitations:
  1. It works only for elements that have click method (e.g. buttons and links).
  2. It cannot be used in code, such as if(confirm("Are you sure?")) because browser execution thread cannot be blocked by JavaScript.
  3. It cannot be used when the button that initiates it performs an AJAX request.


  • New: The predefined dialogs (radalert, radconfirm and radprompt) can be now called by using the new server methods RadAlert, RadConfirm and RadPrompt of the RadWindowManager

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <%@ Register TagPrefix="qsf" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="qsf" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="qsf" Namespace="Telerik.QuickStart" %>

    <%@ Page AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="Telerik.Web.Examples.Window.BrowserDialogBoxes.DefaultCS"
        Language="c#" %>

    <!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 runat="server" ID="Headtag1"></qsf:HeadTag>
        <!-- custom head section -->
        <!-- end of custom head section -->
        <style type="text/css">
            * + html .PostbackButton, * html .PostbackButton
            {
                margin-left: 15px;
            }
        </style>
        <script type="text/javascript">
                            //<![CDATA[

            function alertCallBackFn(arg) {
                radalert("<strong>radalert</strong> returned the following result: <h3 style='color: #ff0000;'>" + arg + "</h3>", null, null, "Result");
            }

            function confirmCallBackFn(arg)
            {
                radalert("<strong>radconfirm</strong> returned the following result: <h3 style='color: #ff0000;'>" + arg + "</h3>", null, null, "Result");
            }

            function promptCallBackFn(arg)
            {
                radalert("After 7.5 million years, <strong>Deep Thought</strong> answers:<h3 style='color: #ff0000;'>" + arg + "</h3>", null, null, "Deep Thought");
            }
                            //]]>                                                                        
        </script>
    </head>
    <body class="BODY">
        <form runat="server" id="mainForm" method="post">
        <qsf:Header ID="Header1" runat="server" NavigationLanguage="c#" />
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <telerik:RadFormDecorator ID="RadFormDecorator1" runat="server" />
        <div class="module" style="width: 90%;">
            <b>Browser GUI: Alert, Prompt, Confirm</b><br />
            <hr />
            <br />
            <telerik:RadWindowManager ID="RadWindowManager1" runat="server" EnableShadow="true">
            </telerik:RadWindowManager>
            <table style="width: 100%;">
                <tr>
                    <td align="center">
                        <h4>
                            Dialogs called from client:
                        </h4>
                        <button style="width: 150px;" onclick="radalert('Radalert is called from the client!', 330, 100,'Client RadAlert', alertCallBackFn); return false;">
                            radalert from client</button><br style="clear: both" />
                        <br style="clear: both" />
                        <button style="width: 150px;" onclick="radconfirm('Client radconfirm: Are you sure?', confirmCallBackFn, 330, 100, null,'Client RadConfirm'); return false;">
                            radconfirm from client</button><br style="clear: both" />
                        <br style="clear: both" />
                        <button style="width: 150px" onclick="radprompt('Client RadPrompt: What is the answer of Life, Universe and Everything?', promptCallBackFn, 330, 160, null, 'Client RadPrompt', '42'); return false;">
                            radprompt from client</button>
                        <br style="clear: both" />
                    </td>
                    <td style="width: 50px;">
                        &nbsp;
                    </td>
                    <td style="border-left: 1px solid #cccccc;" align="center">
                        <br />
                        <h4>
                            Dialogs called from server:
                        </h4>
                        <telerik:RadAjaxPanel ID="pnl1" runat="server">
    <asp:Button ID="btnAlert" Width="150" runat="server" OnCommand="Btn_OnCommand" Text="radalert from server"
    CommandArgument="radalert" />

                            <br style="clear: both" />
                            <br style="clear: both" />
    <asp:Button ID="btnConfirm" Width="150" runat="server" OnCommand="Btn_OnCommand"
    Text="radconfirm from server" CommandArgument="radconfirm" /><br style="clear: both" />

                            <br style="clear: both" />
    <asp:Button ID="btnPrompt" Width="150" runat="server" OnCommand="Btn_OnCommand" Text="radprompt from server"
    CommandArgument="radprompt" />

                        </telerik:RadAjaxPanel>
                        <br style="clear: both" />
                    </td>
                </tr>
            </table>
            <script type="text/javascript">
                //the following code use radconfirm to mimic the blocking of the execution thread.
                //The approach has the following limitations:
                //1. It works inly for elements that have *click* method, e.g. links and buttons
                //2. It cannot be used in if(!confirm) checks
                window.blockConfirm = function (text, mozEvent, oWidth, oHeight, callerObj, oTitle)
                {
                    var ev = mozEvent ? mozEvent : window.event; //Moz support requires passing the event argument manually
                    //Cancel the event
                    ev.cancelBubble = true;
                    ev.returnValue = false;
                    if (ev.stopPropagation) ev.stopPropagation();
                    if (ev.preventDefault) ev.preventDefault();

                    //Determine who is the caller
                    var callerObj = ev.srcElement ? ev.srcElement : ev.target;

                    //Call the original radconfirm and pass it all necessary parameters
                    if (callerObj)
                    {
                        //Show the confirm, then when it is closing, if returned value was true, automatically call the caller's click method again.
                        var callBackFn = function (arg)
                        {
                            if (arg)
                            {
                                callerObj["onclick"] = "";
                                if (callerObj.click) callerObj.click(); //Works fine every time in IE, but does not work for links in Moz
                                else if (callerObj.tagName == "A") //We assume it is a link button!
                                {
                                    try
                                    {
                                        eval(callerObj.href)
                                    }
                                    catch (e) { }
                                }
                            }
                        }

                        radconfirm(text, callBackFn, oWidth, oHeight, callerObj, oTitle);
                    }
                    return false;
                }
            </script>
        </div>
        <br />
        <qsf:InformationBox ID="InformationBox1" runat="server">
            The button below defines a custom code in its OnClientClick event that uses radconfirm
            to mimic the blocking of the execution thread.
            <br />
            The approach has the following limitations:<br />
            <ol>
                <li>It works only for elements that have <strong>click</strong> method (e.g. buttons
                    and links). </li>
                <li>It cannot be used in code, such as <span style="font-family: Courier New">if(confirm("Are
                    you sure?"))</span> because browser execution thread cannot be blocked by JavaScript.
                </li>
                <li>It cannot be used when the button that initiates it performs an AJAX request.
                </li>
            </ol>
        </qsf:InformationBox>
        <br />
    <asp:Button CssClass="PostbackButton" ID="PostbackButton1" runat="server" Text="Confirm postback with radconfirm"
    OnClientClick="return blockConfirm('Are you sure you want to postback?', event, 330, 100,'','Custom title');"
    OnClick="PostbackButton1_Click" />

        <asp:Label ID="Label1" runat="server"></asp:Label>
        <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