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

Contenxt Menu Confirm

1 Answer 60 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Stephen
Top achievements
Rank 2
Stephen asked on 22 Jan 2009, 10:50 PM
I got what I wanted working very quickly because the control works well but got stuck on the last feature. I had a tree that the user could click on but they wanted edit|delete|view option and I added that easily. But I wanted a confirmation on the delete. I tried to catch the OnClientContextMenuItemClicked but then there is no functionality on the tree at all and it looks like I have to handle it all myself. The only other option is going through the postback to raise a new dialog to ask for confirmation.

Anyone have a quicker way to do this? All I want to do is confirm the delete option.

Stephen

Updated: ok, I must have done something wrong because I can call the clientside function and it still acts properly. Is there a way I can change what happens after I return from the client side function. What I'd like it to be able to affect or cancel the server side post under certain conditions.

Updated: ok, never mind, this was as simple as I had hoped it would be

function TestIt(sender, eventArgs) {
  var item = eventArgs.get_menuItem();
  if (item.get_text() == "Delete") {
    if (!confirm("Do you really want to delete that item")) {
      eventArgs.set_cancel(true);
    }
  }



1 Answer, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 23 Jan 2009, 05:21 AM
Hi Stephen,

Try the following client side  function attached with OnClientContextMenuItemClicking instead of OnClientContextMenuItemClicked, in order to cancel the server side ContextMenu click event.

<script type="text/javascript"
function TestIt(sender, eventArgs) 
    var item = eventArgs.get_menuItem(); 
    if (item.get_text() == "Delete"
    { 
        if (!confirm("Do you really want to delete that item")) 
        { 
            eventArgs.set_cancel(true); 
            sender.get_contextMenus()[0].hide(); 
        } 
    } 
</script> 

ASPX:
<telerik:RadTreeView ID="RadTreeView1" Runat="server" OnClientContextMenuItemClicking="TestIt" oncontextmenuitemclick="RadTreeView1_ContextMenuItemClick"

Thanks,
Shinu.
Tags
TreeView
Asked by
Stephen
Top achievements
Rank 2
Answers by
Shinu
Top achievements
Rank 2
Share this question
or