New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

Show a User Confirmation Dialog and Initiate an AJAX Request

Environment

Product Progress® Telerik® UI for ASP.NET AJAX AjaxManager Progress® Telerik® UI for ASP.NET AJAX AjaxPanel

Description

How can I show a confirmation dialog for the user and initiate an Ajax request if accepted with the Telerik UI for ASP.NET AjaxManager or AjaxPanel?

Solution

The following snippet shows the application of standard postbacks.

<asp:ImageButton ID="ImageButton1" runat="server" OnClientClick="return confirm('Are you sure?');" />

To achieve the desired behavior, you need to change the OnClientClick event settings. The purpose is to make it work with AJAX when the button is AJAX-enabled by adding AJAX setting to the AjaxManager or when the button is placed within a AjaxPanel.

<asp:ImageButton ID="ImageButton2" runat="server" OnClientClick="if (!confirm('Are you sure?')) return false;" />

Alternatively, use the OnRequestStart client-side event to implement more complex logic. The following example demonstrates how to display a confirmation message by setting OnRequestStart.

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
            function OnRequestStart(ajaxControl, eventArgs) {
                var eventTarget = eventArgs.get_eventTarget(); 
                if (eventTarget == "<%= ImageButton1.UniqueID %>") {
                    return confirm('Are you sure?');
                }
                else {
                    return false;
                }
            }
</script>
</telerik:RadCodeBlock>

See Also

In this article