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

OnClientContextMenuItemClicked And Return Confirm

4 Answers 176 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Inge Wandsvik
Top achievements
Rank 1
Inge Wandsvik asked on 30 Apr 2008, 11:52 AM
I have a RadTreeView (RadControls Ajax Q1 2008 1.415) with ContextMenu. When I click an item in the ContextMenu called "Delete", I want to show a confirm messagebox. What happens now is that it run a postback no matter what (the ContextMenu item has PostBack=true), but I want to stop this if the user clicks "Cancel" in the confirm messagebox.

Here is my javascript function (called from OnClientContextMenuItemClicked):
    function onClientContextMenuItemClicked(sender, args)  
    {  
        var menuItem = args.get_menuItem();  
        var treeNode = args.get_node();  
 
        switch(menuItem.get_value())  
        {  
            case "Edit":  
                break;  
            case "Delete":  
                return confirm('Are you sure?');  
                break;  
        }  
    }  
 
Anyone with a solution?

4 Answers, 1 is accepted

Sort by
0
Accepted
Veselin Vasilev
Telerik team
answered on 30 Apr 2008, 12:25 PM
Hello Inge Wandsvik,

You need to subscribe to the OnClientContextMenuItemClicking instead of OnClientContextMenuItemClicked.

To cancel the event you can use:

eventArgs.set_cancel(!confirm('Are you sure?'));

I hope this helps.

Sincerely yours,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Inge Wandsvik
Top achievements
Rank 1
answered on 30 Apr 2008, 12:32 PM
Thanks a lot. It works :-)
0
Matt
Top achievements
Rank 2
answered on 07 May 2008, 10:03 PM
Can you do this with the radconfirm I tried this and it just posts back is there an example of this with the rad confirm??
0
Nikolay
Telerik team
answered on 08 May 2008, 10:59 AM
Hello Matthew Todd,

Unfortunately, this cannot be easily achieved and might lead to some side effects. I would rather suggest that you use the standard confirm method instead to cancel the postback.

Regards,
Nick
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
TreeView
Asked by
Inge Wandsvik
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Inge Wandsvik
Top achievements
Rank 1
Matt
Top achievements
Rank 2
Nikolay
Telerik team
Share this question
or