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

confirm popup for radtree contextmenu delete item

6 Answers 222 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
nagarjun
Top achievements
Rank 1
nagarjun asked on 28 Jan 2009, 06:23 AM
Hi,

Radtree has context menus (new, edit, delete). For this switch statement is written .cs page. For delete option clicked in context menu i have to confirm to delete r not. If yes then written to switch statement in .cs page. Please reply me as soon as possible.

For this i have used script in this way .. but not working.

<

script type="text/javascript">

 

function

confirmfun()

 

{

if

(confirm('r u sure u want to delete'))

 

return

true;

 

else

return false;

 

}

</

script>

 



in aspx.cs page :

 

public

void menuclick(object sender, Telerik.Web.UI.RadTreeViewContextMenuEventArgs e)

 

{

 

switch (e.MenuItem.Text)

 

{

 

case "delete":

 

treecontextmenu.Attributes.Add(

"onclick", "return confirmfun()");

 

 

 

if (e.Node.Nodes.Count.Equals(0))

 

{

e.Node.Remove();

}

 

else

 

Response.Write(

"<script> alert('deletion is not possible')</script>");

 

 

break;

 

}

}

 

6 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 28 Jan 2009, 11:37 AM
Hello Nagarjun,

Try the below code snippets to achieve the desired scenario. Attach the OnClientContextMenuItemClicking event to RadTreeView.

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

CS:
protected void RadTreeView1_ContextMenuItemClick(object sender, Telerik.Web.UI.RadTreeViewContextMenuEventArgs e)   
{   
    switch (e.MenuItem.Text)   
    {   
        case "Delete":          //Delete the node   
            if (e.Node.Nodes.Count.Equals(0))   
            {   
                e.Node.Remove();   
            }   
            break;   
        case "Add":   
            {   
            }   
            break;   
        default:   
            {   
            }   
            break;   
    }   
}  

Thanks,
Princy.
0
nagarjun
Top achievements
Rank 1
answered on 29 Jan 2009, 04:13 AM
Hi Princy,

   Thanks.. it was helpful to me. And can u please tell me any site where we can get command on javascript from scratch.

   And in my code y script didnt activate, when i have added attribites in case:delete function.


Thanks,
Nagarjun S.
0
Jeppe
Top achievements
Rank 1
answered on 17 Feb 2009, 04:13 AM
Hi

Im trying to use the same Javascript to cancel somthing but the

 eventArgs.set_cancel(true);    

part doest not work. Get this error "Object doesn't support this property or method"

Any idea of what I could be doing wrong?





0
Princy
Top achievements
Rank 2
answered on 17 Feb 2009, 05:42 AM
Hello Jeppe,

Check whether you attached the OnClientContextMenuItemClicking event or OnClientContextMenuItemClicked. Because OnClientContextMenuItemClicked event not have the set_cancel() function and that can be the cause of getting error. Could you provide some additional information about the setup that you tried? Checkout the links.
OnClientContextMenuItemClicking
OnClientContextMenuItemClicked

Thanks,
Princy.
0
Jeppe
Top achievements
Rank 1
answered on 17 Feb 2009, 06:54 AM
Hi Princy

That sure did it!

Thanks a lot.

Jeppe
0
Darren Fuller
Top achievements
Rank 2
answered on 21 Feb 2009, 05:52 PM

This example worked well. However, I noticed that if you use both the OnClientContextMenuItemClicking and OnClientContextMenuItemClicked at the same time there seems to be a conflict, so I just had to use the Clicking.

Thanks for the example!

Tags
TreeView
Asked by
nagarjun
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
nagarjun
Top achievements
Rank 1
Jeppe
Top achievements
Rank 1
Darren Fuller
Top achievements
Rank 2
Share this question
or