How to use RadConfirm in a Similar way like Confirm

6 posts, 0 answers
  1. Asif
    Asif avatar
    5 posts
    Member since:
    Nov 2013

    Posted 03 Nov 2013 Link to this post

    I have scenarios like : 
    function hello() {
    if(confirm("hello"))
    alert("yes");
    else
    alert("no");
    }

    I wanted to confirm this confirm to radconfirm. so I wrote a code like : 
    function hello(){
         showconfirm();
          if (test) {
           alert("yes");//Here I might use some local variables
          }
          else
            alert("Cancelled");//Here I might use some local variables
        }
     
      function showconfirm() {
        radconfirm("Hello", confirmCallbackFunction);
      }
      function confirmCallbackFunction(arg) {
        test = arg;
      }

    As radconfirm is non-blocking so an alert with "Cancelled" is always prompted without waiting for the value set from the radconfirm.. I can't do all the works in confirmCallbackFunction function because I will have some local variables in hello() function. In this case how can I use blocking radcofirm ?

    I mean , I want to block the further code processing until a button is clicked from the confirm. I want the further codes to be processed after clicking one button in confirm. Thanks in advance for your help.
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 03 Nov 2013 Link to this post

    Hi Asif,

    Please have a look into the following sample code I tried for your scenario.

    ASPX:
    <telerik:RadWindowManager ID="RadWindowManager1" runat="server">
    </telerik:RadWindowManager>
    <telerik:RadButton ID="RadButton1" runat="server" Text="Click" OnClientClicking="confirmClick"
        OnClick="RadButton1_Click">
    </telerik:RadButton>

    JavaScript:
    <script type="text/javascript">
        var test;
        function confirmClick(sender, args) {
            function callBackFunction(arg) {
                test = arg;
                if (test == true) {
                    alert("Yes");
                    $find("<%=RadButton1.ClientID %>").click();
                }
                else {
                    alert("Cancelled");
                }
            }
            radconfirm("Are you sure?", callBackFunction, 300, 160, null, "RadConfirm");
            args.set_cancel(true);
        }
    </script>

    Thanks,
    Shinu.
  3. Asif
    Asif avatar
    5 posts
    Member since:
    Nov 2013

    Posted 04 Nov 2013 Link to this post

    Please Consider my scenario : 

    function chkIsGlobal_Click(checkbox)
        {
          var chkBox = document.getElementById(checkbox);
          var retVal = false;
            if(chkBox.checked == true)
            {
                if( document.getElementById('<% = hfShowExclusive.ClientID %>').value != "false")
                {
                  radconfirm("Hello", function ConfirmCallBack(arg) {
                    if (arg)
                      retVal = true;
                    else {
                      chkBox.checked = false;
                      retVal = false;
                    }
                  }, 500, 120, null, "");
                }
                else
                {
                  retVal = true;
                }
            }
            else
              retVal = true;
           
          alert(retVal);
           
          return retVal; //returning false as
        }

    and this is introduced from code behind. 
    chkGlobal.Attributes.Add("onClick", "if(!chkIsGlobal_Click('" + chkGlobal.ClientID + "')) return;");

    the radconfirm window appears..But without waiting for the result decided from the prompt the code is returning a value false. How can I solve this porblem ?
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 05 Nov 2013 Link to this post

    Hi Asif,

    RadWindowManager's popups such as radconfirm cannot block the execution thread like the standard browser popups (confirm, prompt, alert) - this is something that cannot be done with JavaScript. That is why with radconfirm and radprompt a ClientCallBack function is used in which (after user's input) the logic should continue. Please check the following code.

    JavaScript:
    <script type="text/javascript">
        function chkIsGlobal_Click(checkbox) {
            var chkBox = document.getElementById(checkbox);
            var retVal = false;
     
            function callBackFunction(arg) {
                if (arg) {
                    retVal = true;
                }
                else {
                    retVal = false;
                    chkBox.checked = false;
                }
                alert(retVal);
                return retVal;
            }
     
            if (chkBox.checked == true) {
                if (document.getElementById('<% = hfShowExclusive.ClientID %>').value != "false") {
                    radconfirm("Are you sure?", callBackFunction, 300, 160, null, "RadConfirm");
                }
                else {
                    retVal = true;
                }
            }
            else {
                retVal = true;
            }
        }
    </script>

    Thanks,
    Shinu.
  5. Asif
    Asif avatar
    5 posts
    Member since:
    Nov 2013

    Posted 05 Nov 2013 Link to this post

    Hi Shinu,
    Thanks for your reply. I have tried you code. A confirm window appears but without waiting for ok or cancel being clicked it returns 'undefined' ;  When I click ok or cancel it doesn't return any thing. Can you please help ? Thanks in advanced.
  6. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 06 Nov 2013 Link to this post

    Hi Asif,

    Unfortunately I couldn't replicate the issue at my end. Please download this sample solution I have prepared for your scenario and check if you can replicate the issue.

    Thanks,
    Shinu.
Back to Top