Skip Navigation LinksHome / Community & Support / Code Library / ASP.NET and ASP.NET AJAX > General and Integration Projects > Using radconfirm() CallBackFunction to perform a postback

Using radconfirm() CallBackFunction to perform a postback

Feed from this thread
  • Posted on Jul 6, 2007 (permalink)

    Requirements

    RadControls version

    RadAjax, RadToolbar, RadWindow

    .NET version

    2.0

    Visual Studio version

    2005

    programming language

    C#

    browser support

    all browsers supported by RadControls


     
    PROJECT DESCRIPTION
    Unlike the standard confim(), radconfirm() cannot block the execution of the thread (this is something that cannot be done with Javascript) and a CallBackFunction is needed.

    The attached project demonstrates a real-life scenario where when clicking one of RadToolbar's buttons we want to ask a confirmation from the user before performing the postback. RadWindowManager and RadToolbar are wrapped in RadAjaxPanel to avoid full page's postback.

    The implementation of such scenario is relatively simple - when the user clicks on the button, we need to make a check what button is clicked and if it is the one which requires confirmation - cancel the postback and call radconfirm().
    Once the user confirms the postback, in the radconfirm's CallBackFunction we will use  __doPostBack to send the information on the server:

    <script type="text/javascript">  
        <%= RadToolbar1.ClientID %>.attachEvent("OnClientClick","Toolbar_ClientClick");  
                              
        function Toolbar_ClientClick(sender, e)  
        {  
            if (sender.CommandName == "Delete")  
            {  
                radconfirm("Delete?", CallBackFn);   
                return false;  
            }  
            else 
            {  
                return true;  
            }  
        }          
     
        function CallBackFn(arg)  
            {  
                if(arg)  
                    {  
                        __doPostBack("<%= RadToolbar1.UniqueID %>""onclick#Delete");  
                    }  
            }  
    </script> 


    in  __doPostBack we are provide the following arguments:
    1. The UniqueID of the RadToolbar - this will allow us to reference the toolbar even if a MasterPage is used
    2. The RadToolBar command that we want to be executed.

    And in the codebehind:

    protected void RadToolbar1_OnClick(object sender, Telerik.WebControls.RadToolbarClickEventArgs e)  
    {  
        Message.Text = "You clicked " +  e.Button.CommandName + " " + DateTime.Now.ToString("hh:mm:ss");  
    Attached files

    Reply

  • Paul avatar

    Posted on Jun 5, 2009 (permalink)

    For now, if you cannot get the radconfirm() working and want to use a regular confirm instead.. please see the code below. (until I figure out why the radconfigm is not showing)
    My situation is the following:
    1: User clicked a button Button1
    2: The Button1 event calls a web service which can either complete the processing or return an indication that the user needs to first make a decision based on the backend business rules.
    3: If the user clicks Yes, I initiate a PostBack via java script to call a different method Button2 event.

    Environment:
    VS2008
    RadControls: ASPNET Ajax Q1 2009

    using System; 
    using System.Data; 
    using System.Configuration; 
    using System.Web; 
    using System.Web.Security; 
    using System.Web.UI; 
    using System.Web.UI.WebControls; 
    using System.Web.UI.WebControls.WebParts; 
    using System.Web.UI.HtmlControls; 
     
    public partial class _Default : System.Web.UI.Page 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            if (!IsPostBack) 
            { 
             //   Message.Text = DateTime.Now.ToString("hh:mm:ss"); 
     
            } 
           // Message.Text = Request.Params["__EVENTARGUMENT"] + "  " + Request.Params["__EVENTTARGET"]; 
        } 
        
        protected void Button1_Click(object sender, EventArgs e) 
        { 
            OpenNewWindow("http://google.com"); 
        } 
     
         public void OpenNewWindow(string url) 
        { 
            //string s = String.Format("<script>confirm('{0}');</script>", url); 
          //  string scp = "<script>radconfirm('Are you sure you want to continue?', CallBackFn);</script>"
           // string pb =  String.Format("<script>__doPostBack('{0}', 'onclick');</script>", Button2.UniqueID); 
            string pbbtn = String.Format("__doPostBack('{0}', 'onclick');", Button2.UniqueID); 
            string confPB = "<script>if(confirm('Are you sure?'))" 
                             + " { " 
                             + pbbtn 
                            + "} else { alert('confirm returned the following result: false');}" 
                            + "</script>"; 
     
            ClientScript.RegisterStartupScript(this.GetType(), "newWindow", confPB); 
        } 
        
     
        protected void Button2_Click(object sender, EventArgs e) 
        { 
            Button2.Text = DateTime.Now.ToString("hh:mm:ss"); 
     
        } 
     

    Reply

  • Paul avatar

    Posted on Jun 5, 2009 (permalink)

    If you have a master page, you can create an abstract base class which your MasterPage can extend and in your base class create the Confirm function as follows:

    =============Base Class===============
    /// <summary> 
            ///  
            /// </summary> 
            /// <param name="url"></param> 
            public void Confirm(string confirmMessage, Control callbackYes, Control callBackCancel) 
            { 
              //  string s = String.Format("<script>confirm('{0}');</script>", confirmMessage); 
              //  string scp = "<script>radconfirm('Called From Master Page?', CallBackFn);</script>"
              //  string pb = String.Format("<script>__doPostBack('{0}', 'onclick');</script>", callbackYes.UniqueID); 
                string pbbtn = String.Format("__doPostBack('{0}', 'onclick');", callbackYes.UniqueID); 
                string pbbtnCancel = String.Format("__doPostBack('{0}', 'onclick');", callBackCancel.UniqueID); 
                string confPB = String.Format("<script>if(confirm('{0}'))", confirmMessage) 
                                 + " { " 
                                 + pbbtn 
                                + "}" 
                                + "else {" 
                                + pbbtnCancel 
                                + "}" 
                                + "</script>"; 
     
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "__Confirm1", confPB); 
            } 
     
            /// <summary> 
            ///  
            /// </summary> 
            /// <param name="confirmMessage"></param> 
            /// <param name="callbackYes"></param> 
            public void Confirm(string confirmMessage, Control callbackYes) 
            { 
                string pbbtn = String.Format("__doPostBack('{0}', 'onclick');", callbackYes.UniqueID); 
                string confPB = String.Format("<script>if(confirm('{0}'))", confirmMessage) 
                                 + " { " 
                                 + pbbtn 
                                + "}" 
                                + "</script>"; 
                this.Page.ClientScript.RegisterStartupScript(this.GetType(), "__Confirm2", confPB); 
            } 
     

    ==================Master Page ============
    public partial class Site : InterfaceMaster 
        { 
            protected void Page_Load(object sender, EventArgs e) 
            { 
     
            }                
        } 


    =================Default.aspx==============
     protected void Button1_Click(object sender, EventArgs e) 
        { 
            MasterPage mp = Page.Master; 
            if (mp is TestingRadConfirm.InterfaceMaster) 
            { 
                (mp as TestingRadConfirm.InterfaceMaster).Confirm("Repointing this PBX will repoint all DIDs in the range. Are you sure you want to continue?", Button2, Button3); 
            } 
        } 
     
        /// <summary> 
        ///  
        /// </summary> 
        /// <param name="sender"></param> 
        /// <param name="e"></param> 
         
        protected void Button2_Click(object sender, EventArgs e) 
        { 
            Button2.Text = DateTime.Now.ToString("hh:mm:ss"); 
            Message.Text = "Button2 click event " + DateTime.Now.ToString("hh:mm:ss"); 
        } 
     
        /// <summary> 
        ///  
        /// </summary> 
        /// <param name="sender"></param> 
        /// <param name="e"></param> 
        protected void Button3_Click(object sender, EventArgs e) 
        { 
            Button3.Text = DateTime.Now.ToString("hh:mm:ss"); 
            Message.Text = "Button3 click event " + DateTime.Now.ToString("hh:mm:ss"); 
        } 

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Code Library / ASP.NET and ASP.NET AJAX > General and Integration Projects > Using radconfirm() CallBackFunction to perform a postback