This is a migrated thread and some comments may be shown as answers.

How to use RadConfirm in a Similar way like Confirm

5 Answers 192 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Asif
Top achievements
Rank 1
Asif asked on 04 Nov 2013, 03:59 AM
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.

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 04 Nov 2013, 05:26 AM
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.
0
Asif
Top achievements
Rank 1
answered on 04 Nov 2013, 06:17 AM
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 ?
0
Shinu
Top achievements
Rank 1
answered on 05 Nov 2013, 08:57 AM
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.
0
Asif
Top achievements
Rank 1
answered on 06 Nov 2013, 04:01 AM
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.
0
Shinu
Top achievements
Rank 1
answered on 06 Nov 2013, 12:33 PM
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.
Tags
General Discussions
Asked by
Asif
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Asif
Top achievements
Rank 1
Share this question
or