oncontextmenuitemclick is not firing

2 posts, 0 answers
  1. dipan
    dipan avatar
    9 posts
    Member since:
    Feb 2010

    Posted 13 Jan 2011 Link to this post

    Hi,
    I am trying to use a context menu in treeview. for demo puropose i have two menu item add and new. when I am click on add context menu then trying to visible a div from server side but its not happening. please see my code below. Thanks.
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ContentMenu.aspx.cs" Inherits="CMSEngine.Web.Admin.Desk.Content.ContentMenu" %>
    <%@ Register assembly="Telerik.Web.UI" namespace="Telerik.Web.UI" tagprefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <div style="float:left; width:350px;">
        <telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
         <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">
                <AjaxSettings>
                    <telerik:AjaxSetting AjaxControlID="DeleteButton">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadTreeView1" LoadingPanelID="RadAjaxLoadingPanel1" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                    <telerik:AjaxSetting AjaxControlID="AddButton">
                        <UpdatedControls>
                            <telerik:AjaxUpdatedControl ControlID="RadTreeView1" LoadingPanelID="RadAjaxLoadingPanel1" />
                        </UpdatedControls>
                    </telerik:AjaxSetting>
                </AjaxSettings>
            </telerik:RadAjaxManager>
            <telerik:RadAjaxLoadingPanel runat="server" ID="RadAjaxLoadingPanel1" />
            <asp:Button ID="DeleteButton" runat="server" OnClick="DeleteButton_Click"
               ValidationGroup="DeleteRequiresSelection" Text="Delete selected node"></asp:Button>
               <br /><br />
         <asp:Button ID="AddButton" runat="server" OnClick="AddButton_Click"
    ValidationGroup="TextRequired" Text="Add new node"></asp:Button>
    <br /> <br /> <telerik:RadTextBox runat="Server" ID="NodeTextBox" EmptyMessage="Enter node text"></telerik:RadTextBox>
    <br /><br />
     
        <telerik:RadTreeView ID="RadTreeView1" Runat="server" CausesValidation="false "
        onnodeclick="RadTreeView1_NodeClick"
                oncontextmenuitemclick="RadTreeView1_ContextMenuItemClick">
            <ContextMenus>
                <telerik:RadTreeViewContextMenu ID="RadTreeViewContextMenu1" runat="server">
                    <Items>
                        <telerik:RadMenuItem runat="server"  Text="Add New Page" PostBack="true" >
                        </telerik:RadMenuItem>
                        <telerik:RadMenuItem runat="server" Text="Remove" PostBack="true">
                        </telerik:RadMenuItem>
                    </Items>
                </telerik:RadTreeViewContextMenu>
            </ContextMenus>
        <DataBindings>
        <telerik:RadTreeNodeBinding Expanded="true" />
        </DataBindings>
    </telerik:RadTreeView>
        </div>
        <div id="divNew" style="float:left; width:450px; padding-left:15px; display:none;" runat="server" >
        <table border="0" cellpadding="0" cellspacing="0">
        <tr>
        <td>Title: </td>
        <td><telerik:RadTextBox ID="txtTile" runat="server" EmptyMessage="Enter page title"></telerik:RadTextBox></td>
        </tr>
        <tr>
        <td>Alias: </td>
        <td><telerik:RadTextBox ID="txtAlias" runat="server" EmptyMessage="Enter page alias"></telerik:RadTextBox></td>
        </tr>
        <tr>
        <td>Path: </td>
        <td><telerik:RadTextBox ID="txtPath" runat="server" EmptyMessage="Enter page path"></telerik:RadTextBox></td>
        </tr>
        <tr>
        <td>LinkURL: </td>
        <td><telerik:RadTextBox ID="txtLinkUrl" runat="server" EmptyMessage="Enter page link"></telerik:RadTextBox></td>
        </tr>
        </table>
        </div>
        </div>
        </form>
    </body>
    </html>
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    using Telerik.Web.UI;
     
    namespace CMSEngine.Web.Admin.Desk.Content
    {
        public partial class ContentMenu : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    SetupTree();
                }
            }
     
            private void SetupTree()
            {
                List<SiteDataItem> items = SiteDataItem.GetSiteData();
                RadTreeView1.DataSource = items;
                RadTreeView1.DataFieldID = "ID";
                RadTreeView1.DataFieldParentID = "ParentID";
                RadTreeView1.DataTextField = "Text";
                RadTreeView1.DataBind();
            }
     
            protected void RadTreeView1_NodeClick(object sender, RadTreeNodeEventArgs e)
            {
     
            }
     
            protected void DeleteButton_Click(object sender, EventArgs e)
            {
                Page.Validate("DeleteRequiresSelection");
                if (Page.IsValid)
                {
                    RadTreeView1.SelectedNode.Remove();
                }
            }
     
            protected void AddButton_Click(object sender, EventArgs e)
            {
                Page.Validate("TextRequired");
                if (Page.IsValid)
                {
                    IRadTreeNodeContainer target = RadTreeView1;
                    if (RadTreeView1.SelectedNode != null)
                    {
                        RadTreeView1.SelectedNode.Expanded = true;
                        target = RadTreeView1.SelectedNode;
                    }
     
     
                    RadTreeNode addedNode = new RadTreeNode(NodeTextBox.Text);
                    addedNode.Selected = true;
                    target.Nodes.Add(addedNode);
                }
            }
     
            public class SiteDataItem
            {
                private string _text;
                private int _id;
                private int _parentId;
     
                public string Text
                {
                    get { return _text; }
                    set { _text = value; }
                }
     
     
                public int ID
                {
                    get { return _id; }
                    set { _id = value; }
                }
     
                public int ParentID
                {
                    get { return _parentId; }
                    set { _parentId = value; }
                }
     
                public SiteDataItem(int id, int parentId, string text)
                {
                    _id = id;
                    _parentId = parentId;
                    _text = text;
                }
     
                public static List<SiteDataItem> GetSiteData()
                {
                    List<SiteDataItem> siteData = new List<SiteDataItem>();
     
                    siteData.Add(new SiteDataItem(1, 0, "Products"));
                    siteData.Add(new SiteDataItem(2, 1, "RadControls for ASP.NET Ajax"));
                    siteData.Add(new SiteDataItem(3, 1, "RadControls for Silverlight"));
                    siteData.Add(new SiteDataItem(4, 2, "RadGrid"));
                    siteData.Add(new SiteDataItem(5, 2, "RadScheduler"));
                    siteData.Add(new SiteDataItem(6, 2, "RadEditor"));
                    siteData.Add(new SiteDataItem(7, 3, "RadGrid"));
                    siteData.Add(new SiteDataItem(8, 3, "RadMenu"));
                    siteData.Add(new SiteDataItem(9, 3, "RadEditor"));
     
                    return siteData;
                }
            }
     
            protected void RadTreeView1_ContextMenuItemClick(object sender, RadTreeViewContextMenuEventArgs e)
            {
                if (e.MenuItem.Text == "Add New Page")
                {
                    divNew.Visible = true;
                }
                else if (e.MenuItem.Text == "Remove")
                {
                    RadTreeView1.SelectedNode.Remove();
                }
            }
     
        }
    }
  2. dipan
    dipan avatar
    9 posts
    Member since:
    Feb 2010

    Posted 13 Jan 2011 Link to this post

    Hi,
    if I Remove the following block and put my form inside the rad panel then its works but I am wondering how to make work with my previous code .
    Thanks.
    <telerik:RadAjaxManager runat="server" ID="RadAjaxManager1">
               <AjaxSettings>
                   <telerik:AjaxSetting AjaxControlID="DeleteButton">
                       <UpdatedControls>
                           <telerik:AjaxUpdatedControl ControlID="RadTreeView1" LoadingPanelID="RadAjaxLoadingPanel1" />
                       </UpdatedControls>
                   </telerik:AjaxSetting>
                   <telerik:AjaxSetting AjaxControlID="AddButton">
                       <UpdatedControls>
                           <telerik:AjaxUpdatedControl ControlID="RadTreeView1" LoadingPanelID="RadAjaxLoadingPanel1" />
                       </UpdatedControls>
                   </telerik:AjaxSetting>
                   <telerik:AjaxSetting AjaxControlID="RadTreeViewContextMenu1">
                       <UpdatedControls>
                           <telerik:AjaxUpdatedControl ControlID="RadTreeViewContextMenu1" LoadingPanelID="RadAjaxLoadingPanel1" />
                       </UpdatedControls>
                   </telerik:AjaxSetting>
               </AjaxSettings>
           </telerik:RadAjaxManager>
Back to Top