confirm popup for radtree contextmenu delete item

7 posts, 1 answers
  1. nagarjun
    nagarjun avatar
    21 posts
    Member since:
    Jan 2009

    Posted 28 Jan 2009 Link to this post

    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;

     

    }

    }

     

  2. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 28 Jan 2009 Link to this post

    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.
  3. nagarjun
    nagarjun avatar
    21 posts
    Member since:
    Jan 2009

    Posted 28 Jan 2009 Link to this post

    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.
  4. Jeppe
    Jeppe avatar
    12 posts
    Member since:
    Jan 2009

    Posted 16 Feb 2009 Link to this post

    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?





  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 Feb 2009 Link to this post

    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.
  6. Jeppe
    Jeppe avatar
    12 posts
    Member since:
    Jan 2009

    Posted 17 Feb 2009 Link to this post

    Hi Princy

    That sure did it!

    Thanks a lot.

    Jeppe
  7. Darren Fuller
    Darren Fuller avatar
    6 posts
    Member since:
    Apr 2005

    Posted 21 Feb 2009 Link to this post

    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!

Back to Top