RadConfirm from code behind

3 posts, 0 answers
  1. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 22 Oct 2010 Link to this post

    Requirements

    RadControls version

    2010, 1, 519, 35
    .NET version

    3.5 SP1
    Visual Studio version

    2008
    programming language

    C#, Javascript
    browser support

    all browsers supported by RadControls


    PROJECT DESCRIPTION
    The project demonstrates how to call a radConfirm from code behind and how to retrieve its response in server side. The radconfirm is shown by following the similar approach described in KB Article and uses ajaxRequest to pass the result to server.

    ASPX:
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="RadConfirm.aspx.cs" Inherits="_Default" %>
     
    <%@ 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">
    <head 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" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
                <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" OnClick="Button2_Click" />
            <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>

    C#:
    protected void Button2_Click(object sender, EventArgs e)
       {
           string radalertscript = "<script language='javascript'>function f(){callConfirm(); Sys.Application.remove_load(f);}; Sys.Application.add_load(f);</script>";
           Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", radalertscript);
       }
       protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
       {
           if (e.Argument.ToString() == "ok")
           {
               Label1.Text="OK";
           }
           else
           {
               Label1.Text = "Cancel";
           }
       }

    Thanks,
    Princy.
  2. Soumya
    Soumya avatar
    108 posts
    Member since:
    Jul 2012

    Posted 26 Jul 2012 Link to this post

    Hi Princy,
    I was trying to implement the same in my code.
    My scenario is like on button click,I need to save a record.Before saving the record,I am doing a check to see if the record already exist.If it exist,then sending a confirm message as 'record already exist.do you want to proceed?'.If the user click 'yes',then I need to continue my saving.Else,need to exit the save process.

    Please find below my code with your radconfirm functions.
    Here I am not getting a confirm window.Please let me know what is the issue in my code.
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="FrmReferraldoctor.aspx.cs" Inherits="FrmReferraldoctor" %>
     
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title></title>
         
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function openWinRefClinic() {
                window.radopen("FrmReferralClinicGrid.aspx", "RefClinicDialog");
            }
     
             
            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>
        </telerik:RadCodeBlock>
         
    </head>
    <body>
        <form id="form1" runat="server">   
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager>
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
            <Windows>          
                <telerik:RadWindow ID="RefClinicDialog" Title="Referral Clinic Data" runat="server" Height="500px" Width="550px"
                    Left="150px" Behaviors="Close" />
            </Windows>
        </telerik:RadWindowManager>
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RCCountry">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RCCity" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RbSave">
                    <UpdatedControls>
             
                        <telerik:AjaxUpdatedControl ControlID="RbSave" />
                        <telerik:AjaxUpdatedControl ControlID="Message" />
                        <telerik:AjaxUpdatedControl ControlID="lblerror" />
                        <telerik:AjaxUpdatedControl ControlID="lblName" />
                        <telerik:AjaxUpdatedControl ControlID="emailValidator" />
                        <telerik:AjaxUpdatedControl ControlID="lblContact" />
                        <telerik:AjaxUpdatedControl ControlID="lblLicence" />   
                        <telerik:AjaxUpdatedControl ControlID="lblScript" />                  
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RbClose">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RbClose" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadAjaxManager1">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="lblScript" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <table width="100%">
        
        <tr>
        <td align="right" >       
            <telerik:RadButton ID="RbSave" runat="server" Text="Save" onclick="RbSave_Click1"
               >
                                <Icon PrimaryIconCssClass="rbSave" PrimaryIconLeft="4" PrimaryIconTop="4" />
                            </telerik:RadButton>
        </td>
        <td>
            <telerik:RadButton ID="RbClose" runat="server" Text="Close"
                style="top: 0px; left: 0px" onclick="RbClose_Click"  >
                                <Icon PrimaryIconCssClass="rbCancel" PrimaryIconLeft="4" PrimaryIconTop="4" />
                            </telerik:RadButton>
        </td>
        <td>
            
            <asp:Label ID="lblScript" runat="server" Text=""></asp:Label>
             
        </td>
        </tr>
        </table>
         
        </form>
    </body>
    </html>

    aspx.cs
    protected void RbSave_Click1(object sender, EventArgs e)
            {
                 //code for checking invalid data
                    //check if record  exist            
     
                    bool check = _refDoctorService.DoctorExists(search);
                    if (check == true) //record exist. show an alert here
                    {
                            string radalertscript = "<script language='javascript'>function f(){callConfirm(); Sys.Application.remove_load(f);}; Sys.Application.add_load(f);</script>";
                            Page.ClientScript.RegisterStartupScript(this.GetType(), "radalert", radalertscript);                   
                        
                    }
                    if (lblScript.Text=="OK")
                    {
                           //code for saving record
                       
                    }
                    else
                    {
                         //exit save
                    }
                }          
                 
            }
     protected void RadAjaxManager1_AjaxRequest(object sender, AjaxRequestEventArgs e)
            {
                if (e.Argument.ToString() == "ok")
                {
                    lblScript.Text = "OK";
                }
                else
                {
                    lblScript.Text = "Cancel";
                }
            }

    Thanks,
    Soumya
  3. Soumya
    Soumya avatar
    108 posts
    Member since:
    Jul 2012

    Posted 26 Jul 2012 Link to this post

    Hi,
    I have got a solution with RadAjaxManager1.ResponseScripts.Add("radconfirm('Are you sure!?', confirmCallBackFn);"); and 2 button click event.

    Thanks,
    Soumya
Back to Top