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

Accessing a custom object in the RadConfirm Callback

3 Answers 164 Views
Window
This is a migrated thread and some comments may be shown as answers.
Imar
Top achievements
Rank 1
Imar asked on 10 Sep 2008, 11:57 AM
Hi there,

The documentation for RadWindow contains the following:


Optionally, you can add additional arguments to supply the dialog with a width, height, and title, as well as an object you can use to pass information you think will be helpful in the callback. This object can be programmer defined or you can send a reference to some HTML object on the page.


My question is, how do I access that object? I figured it would work like this:

// Code calling radconfirm
var myState = 'Some State';
radconfirm('Are you sure', MyCallBack, 300, 300, myState, 'Delete');

Then I could have the following call back handler:

function MyCallBack(arg, state)
{
  if (arg)
  {
    alert(state); // would alert the text 'Some State'
  }
}

This is the way many other callback handlers normally work. However, no matter what I try, state is always null.

Any ideas? Am I overlooking something? Or is the documention incorrect?

Kind regards,

Imar

3 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 11 Sep 2008, 11:37 AM
Hello Imar,

The callback function for radconfirm() accepts only one argument. Here is how you can use additional argument in it:

function confirmation() 
 
        function MyCallBack(arg) 
        { 
            alert(arg + " " + myState);  
        } 
     
      var myState = 'Some State';  
    radconfirm('Are you sure', MyCallBack, 300, 300, myState, 'Delete'); 



Greetings,
Georgi Tunev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Patrick Maurer
Top achievements
Rank 1
answered on 19 Sep 2008, 02:21 PM
Why isn't that in the documentation or in the samples?$0$0$0$0I just spent nearly an hour just trying to get that additional object into the callback method...$0$0$0$0$0First: A developer would expect the confirm dialog call to be blocking and return only when a button is pressed. You wouldnt expect the dialog to return immediatly and using a callback.$0$0$0$0$0Second: You would expect the addiotional object either as a .object property on the args parameter or as a second parameter in the callback.$0$0No normal developer would ever get the idea by heart, that you need to define the callback function in the scope of the additional object just to use that.$0$0$0$0$0If you do such strange and non-intuitive things in your API, please document that at that very moment. Spending hours to research such strange behaviour is ver annoying. And if Imar wouldnt have had that very same issue I would be researching the issue for another hour and posting a support ticket finally... just for a thing you should have put in the documentation...$0
0
Tervel
Telerik team
answered on 23 Sep 2008, 09:04 AM
Hello Patrick,

The help information that you quote is misleading, and it seems to have been copy/pasted from RadWindow Classic without due editing. This information will be promptly updated - for the coming Q2 SP2.

That said, from your additional comments I understand that extra information about how JavaScript and DHTML work will be helpful:

"First: A developer would expect the confirm dialog call to be blocking and return only when a button is pressed."
That is correct. And we very much would like to do so. Unfortunately it is not possible. Only system browser dialogs - such as alert, prompt, confirm can cause the JavaScript execution thread to block. It is simply not possible to block the thread using script. This is why, unlike desktop programming the client-side JavaScript model relies exclusively on callback events. This is especially visible in AJAX programming - if you examine the ASP.NET MS AJAX documentation you will note that the asynchronous methods usually require two callback handlers - that is, "onsuccess" and "onerror" handlers.

"You wouldnt expect the dialog to return immediatly and using a callback."
Yet, there is no choice (see above explanation ).

"
Second: You would expect the addiotional object either as a .object property on the args parameter or as a second parameter in the callback."
Technically speaking, the callback method is not an event-handler method  of the familiar function(sender, args) kind.
However, the fault here is mainly with the misleading information in our documentation that is being corrected.

"No normal developer would ever get the idea by heart, that you need to define the callback function in the scope of the additional object just to use that."
This is a common technique in JavaScript.  It is just one possible way, and not the only one, of approaching the scenario you need. Function nesting (closures) creates scope and allows to better encapsulate your code. That said, the same result could have been implemented without using closures. Client-side development, like any other platform and language has its capabilities and rules, and closures are one such option. It is a normal language feature that has nothing to do with Telerik controls - it just comes in handy in this particular scenario.

"If you do such strange and non-intuitive things in your API, please document that at that very moment."
The information and the example in the documentation will be updated - in that respect we fully agree with you.

Best regards,
Tervel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Window
Asked by
Imar
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Patrick Maurer
Top achievements
Rank 1
Tervel
Telerik team
Share this question
or