If you are using some of the predefined modal dialogs part of RadWindow: Alert, Prompt and Confirm you may find this article quite handy.
As you know the calls to these methods are asynchronous, thus you cannot stop the current UI thread in order to get the user feedback from the windows synchronously. This introduces some issues such as the need to declare class member variables whenever they may not be necessary. Due to that there have been a few requests on our support website to create a generic parameter inside the static calls of the dialogs with the purpose of carrying object for further actions, and avoid the declaration of class member variables. Instead of limiting you to a generic Action delegate with one parameter, we concluded that it will be handier if you just create an anonymous method and implement your logic there. To read more about anonymous methods refer to this website.
To demonstrate the best use of anonymous methods consider the following example. I will create a simple navigation control that hosts two buttons.
To make the things simpler I will just use one method for handling the buttons’ callbacks. Now we want to use a Confirm dialog to confirm the opening of a page. As I explained before, the constraint of having only asynchronous calls to our dialogs means that we have to “store” the result of this callback(the button clicked), and perform some actions depending on it after we get response from the user like this:
Storing the value in a class member variable may not be considered as a best practice, since the variable may not be further used. Using anonymous methods we can simplify the implementation of the button callback to this:
Note: No use of class member variable.
Hristo Borisov (@hristoborisov) is currently a product line manager in Telerik leading all cloud technologies part of the Telerik Platform after spending more than 6 years with the company. A passionate advocate of applying lean startup practices to existing organizations, Hristo is on the quest for discovering scalable and sustainable business models through product and customer development using tools like MVPs, Pivots, and Lean Business Model Canvases.