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

radconfirm block thread

1 Answer 99 Views
Window
This is a migrated thread and some comments may be shown as answers.
G.
Top achievements
Rank 1
G. asked on 12 Apr 2012, 07:00 PM
I have a RadComboBox which is setup as follows

 

 

 

<telerik:RadComboBox ID="radcombo_1" AutoPostBack="true" runat="server" 
    onselectedindexchanged="radcombo_1_SelectedIndexChanged" OnClientSelectedIndexChanging="SelectionChange" >
</telerik:RadComboBox>

My goal is to prevent a selection change in certain scenarios.  Currently, I enforce this using good ole'
js window.confirm as follows

function SelectionChange(sender, eventArgs) {
    try {                
        var text = "";                
        text = sender.get_text();
        if (text != "Select") {
            var allow = false;
            allow = TheConfirm();
            if (allow == true) {
                eventArgs.set_cancel(false);
            }
            else {
                eventArgs.set_cancel(true);
            }
        }
    }
    catch (errA) {
                    }
}

function TheConfirm() {
     return confirm("Change?");                     
}

However, I would like to change this to utilize radconfirm with a <ConfirmTemplate>.  Yet, radconfirm does not appear to be a blocking call...

Can anyone provide an example of how to prevent the RadComboBox selection change with a blocking radconfirm that uses a custom <ConfirmTemplate>???

Any help would be greatly appreciated. 

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 17 Apr 2012, 11:40 AM
Hello,

Generally blocking the execution with the RadConfirm is not possible. This is due to the fact that only native code can do this, while the RadConfirm is user JavaScript, no built-in the browser. This is explained in this help article and this online demo.

This means that in order to use the RadConfirm in this manner you must cancel the original execution and complete the work with JavaScript. This is not always possible and in some scenarios the browser confirm() cannot be replaced with the RadConfirm.

Nevertheless, I prepared and attached a small sample for you that asks for confirmation of the selection. I tried to base it on your logic, yet you can further modify it as needed. Note how I am using the RadComboBox's client-side API in the callback function of the RadConfirm to do the necessary work.

As for using templates - as long as the correct buttons are present (i.e. the RadConfirm returns the expected results) - this will not be a problem. Changing the template is explained in this help article.


Regards,
Marin
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Window
Asked by
G.
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or