RadGrid drag and drop in MOSS webpart

8 posts, 1 answers
  1. Tarık
    Tarık avatar
    3 posts
    Member since:
    Jul 2008

    Posted 16 Jul 2008 Link to this post

    Hi folks,
    I am trying to use Radgrid drag and drop demo (that is related with pendingOrders and shippedOrders)  inside a sharepoint web part. I have made appropriate changes for Ajax integration of my sharepoint web application inside web.config. Adding assemblies to GAC and to web.config as safe controls are succesfully completed. I can see my controls that has been created in CreateChildControls Method in the page. I can select rows multiplely from pendingOrders radgrid and can drop them to shippingOrders grid as ajax based. Everything is ok for the first time, but then and I want to choose new rows to drag and drop again but I can chose nothing. It seems like there is no client script after ajax base post. I looked at the ClientID 's of two radgrid controls on my page and they don't change during ajax xmlhttpresquest. If I refresh the page everything is ok again, but just for the first drag and drop, for the second it is not available to chose another row. I have taken this sample demo from Telerik site and tried to integrate it to a web part. the demo in the site has been developed for normal ASP.NET pages. But because of web part architecture it is not possible to use a designer. I have to create radgrids, Radajaxmanager, radloodingpanel and etc dynamically in CreateChildControls of webpart. Is there any sample of creating radgird dynamically in CreateChildControls.

    Here is my web part code: You can compile it and test. Every data has been stored in Session and taken back to use.

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Runtime.InteropServices;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Serialization;
    using System.Data.SqlClient;
    using System.Web.UI.HtmlControls;
    using TTNetAv.Portal.Audio;
    using TTNetAv.Core;
    using TTNetAv.Core.Domain;
    using System.Collections.Generic;
    using System.Web.Caching;
    using Telerik.Web.UI;
    using System.Web;
    using Microsoft.SharePoint.WebPartPages;

    namespace TTNetAv.Test.Web.WebPart
    {
        public class DenemeWebPart : System.Web.UI.WebControls.WebParts.WebPart
        {
            protected Telerik.Web.UI.RadGrid grdShippedOrders;
            protected Telerik.Web.UI.RadGrid grdPendingOrders;
            protected Button Button1;
            protected TextBox TextBox1;
            protected Telerik.Web.UI.RadAjaxLoadingPanel ralp;
            protected Telerik.Web.UI.RadAjaxManager ram;
            protected Telerik.Web.UI.RadScriptBlock rsb;
            protected HtmlGenericControl javaScr;
            protected HtmlGenericControl msg;
            protected HyperLink hl;
            private ScriptManager _AjaxManager;

            #region Events & Fixers
           

            [Microsoft.SharePoint.WebPartPages.WebPartStorage(Storage.None)]
            public ScriptManager AjaxManager
            {
                get { return _AjaxManager; }
                set { _AjaxManager = value; }
            }

            protected override void OnInit(EventArgs e)
            {
                base.OnInit(e);
                _AjaxManager = ScriptManager.GetCurrent(this.Page);
                if (_AjaxManager == null)
                {
                    _AjaxManager = new ScriptManager();
                    _AjaxManager.EnablePartialRendering = true;
                    _AjaxManager.EnableScriptLocalization = true;
                    Page.ClientScript.RegisterStartupScript(typeof(DenemeWebPart), this.ID, "_spOriginalFormAction = document.forms[0].action;", true);
                    if (this.Page.Form != null)
                    {
                        string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
                        if (!string.IsNullOrEmpty(formOnSubmitAtt) && formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
                        {
                            this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
                        }
                        this.Page.Form.Controls.AddAt(0, _AjaxManager);
                    }
                }
                EnsureChildControls();
            }


            protected override void OnPreRender(EventArgs e)
            {
                base.OnPreRender(e);
            }

            private void EnsurePanelFix()
            {
                if (this.Page.Form != null)
                {
                    String fixupScript = @"
                                        _spBodyOnLoadFunctionNames.push(""_initFormActionAjax"");
                                         function _initFormActionAjax()
                                         {
                                           if (_spEscapedFormAction == document.forms[0].action)
                                           {
                                             document.forms[0]._initialAction =
                                             document.forms[0].action;
                                           }
                                         }
                                         var RestoreToOriginalFormActionCore =
                                           RestoreToOriginalFormAction;
                                         RestoreToOriginalFormAction = function()
                                         {
                                           if (_spOriginalFormAction != null)
                                           {
                                             RestoreToOriginalFormActionCore();
                                             document.forms[0]._initialAction =
                                             document.forms[0].action;
                                           }
                                         }";

                    ScriptManager.RegisterStartupScript(this,
                      typeof(DenemeWebPart), "UpdatePanelFixup",
                      fixupScript, true);
                }
            }

            protected override void Render(HtmlTextWriter writer)
            {
                EnsureUpdatePanelFixups();
                base.Render(writer);
            }


            private void EnsureUpdatePanelFixups()
            {
                if (this.Page.Form != null)
                {
                    string formOnSubmitAtt = this.Page.Form.Attributes["onsubmit"];
                    if (formOnSubmitAtt == "return _spFormOnSubmitWrapper();")
                    {
                        this.Page.Form.Attributes["onsubmit"] = "_spFormOnSubmitWrapper();";
                    }
                }

                ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "UpdatePanelFixup", "_spOriginalFormAction = document.forms[0].action; _spSuppressFormOnSubmitWrapper=true;", true);
            }

            #endregion


            protected override void CreateChildControls()
            {
              

                EnsurePanelFix();

                msg = new HtmlGenericControl("div");
                msg.EnableViewState = false;
                msg.InnerText = "deneme";

                Button1 = new Button();
                Button1.ID = "Button1";
                Button1.Text = "Search";
                Button1.Click += new EventHandler(Button1_Click);

                TextBox1 = new TextBox();
                TextBox1.ID = "TextBox1";

                hl = new HyperLink();
                hl.ID = "trashCan";
                hl.Text = "Çöplük";
                hl.Attributes.Add("onclick", "return false;");
              

                grdPendingOrders = new RadGrid();
                grdPendingOrders.ID = "grdPendingOrders";
                grdPendingOrders.Skin = "Sunset";
                grdPendingOrders.AllowPaging = true;
                grdPendingOrders.NeedDataSource += new GridNeedDataSourceEventHandler(grdPendingOrders_NeedDataSource);
                grdPendingOrders.RowDrop += new GridDragDropEventHandler(grdPendingOrders_RowDrop);
                grdPendingOrders.AllowMultiRowSelection = true;
                grdPendingOrders.Width = 350;
                grdPendingOrders.MasterTableView.DataKeyNames = new string[] { "OrderId" };
                grdPendingOrders.ClientSettings.AllowRowsDragDrop = true;
                grdPendingOrders.ClientSettings.Selecting.AllowRowSelect = true;
                grdPendingOrders.ClientSettings.Selecting.EnableDragToSelectRows = true;
                grdPendingOrders.ClientSettings.ClientEvents.OnRowDropping = "onRowDropping";


                grdShippedOrders = new RadGrid();
                grdShippedOrders.ID = "grdShippedOrders";
                grdShippedOrders.Skin = "Hay";
                grdShippedOrders.AllowPaging = true;
                grdShippedOrders.NeedDataSource += new GridNeedDataSourceEventHandler(grdShippedOrders_NeedDataSource);
                grdShippedOrders.RowDrop += new GridDragDropEventHandler(grdShippedOrders_RowDrop);
                grdShippedOrders.AllowMultiRowSelection = true;
                grdShippedOrders.Width = 350;
                grdShippedOrders.MasterTableView.DataKeyNames = new string[] { "OrderId" };
                grdShippedOrders.MasterTableView.RowIndicatorColumn.HeaderStyle.Width = 20;
                grdShippedOrders.MasterTableView.ExpandCollapseColumn.HeaderStyle.Width = 20;
                grdShippedOrders.ClientSettings.AllowRowsDragDrop = true;
                grdShippedOrders.ClientSettings.Selecting.AllowRowSelect = true;
                grdShippedOrders.ClientSettings.Selecting.EnableDragToSelectRows = false;
                grdShippedOrders.ClientSettings.ClientEvents.OnRowDropping = "onRowDropping";



              


                ralp = new RadAjaxLoadingPanel();
                ralp.ID = "RadAjaxLoadingPanel";
                ram = new RadAjaxManager();
                ram.ID = "radAjax";
                ram.DefaultLoadingPanelID = "RadAjaxLoadingPanel";

                Telerik.Web.UI.AjaxSetting asd = new Telerik.Web.UI.AjaxSetting();
                asd.AjaxControlID = "Button1";
                asd.UpdatedControls.Add(new Telerik.Web.UI.AjaxUpdatedControl("TextBox1", "ralp"));
                asd.UpdatedControls.Add(new Telerik.Web.UI.AjaxUpdatedControl("grdPendingOrders", "ralp"));

                ram.AjaxSettings.Add(asd);


                Telerik.Web.UI.AjaxSetting asd1 = new Telerik.Web.UI.AjaxSetting();
                asd1.AjaxControlID = "grdPendingOrders";
                asd1.UpdatedControls.Add(new Telerik.Web.UI.AjaxUpdatedControl("grdPendingOrders", "ralp"));
                asd1.UpdatedControls.Add(new Telerik.Web.UI.AjaxUpdatedControl("grdShippedOrders", "ralp"));
                asd1.UpdatedControls.Add(new Telerik.Web.UI.AjaxUpdatedControl("msg", "ralp"));

                ram.AjaxSettings.Add(asd1);



                Telerik.Web.UI.AjaxSetting asd2 = new Telerik.Web.UI.AjaxSetting();
                asd2.AjaxControlID = "grdShippedOrders";
                asd2.UpdatedControls.Add(new Telerik.Web.UI.AjaxUpdatedControl("grdShippedOrders", "ralp"));
                asd2.UpdatedControls.Add(new Telerik.Web.UI.AjaxUpdatedControl("msg", "ralp"));

                ram.AjaxSettings.Add(asd2);


                javaScr = new HtmlGenericControl();
                javaScr.TagName = "script";
                javaScr.Attributes["type"] = "text/javascript";
                string gridscript = @"
                        function onRowDropping(sender, args)
                        {
                            if (sender.get_id() == '" + grdPendingOrders.ClientID+ @"')
                            {
                                var node = args.get_destinationHtmlElement();
                                if(!isChildOf('" + grdShippedOrders.ClientID + @"', node) && !isChildOf('" + grdPendingOrders.ClientID + @"', node) )
                                {
                                    args.set_cancel(true);
                                }
                            }
                            else
                            {
                                var node = args.get_destinationHtmlElement();
                                if(!isChildOf('trashCan', node))
                                {
                                    args.set_cancel(true);
                                }
                                else
                                {
                                    if (confirm('Are you sure you want to delete this order?'))
                                        args.set_destinationHtmlElement('trashCan');
                                    else
                                       args.set_cancel(true);
                                }
                            }
                        }
                       
                        function isChildOf(parentId, element)
                        {
                            while(element)
                            {
                                if (element.id && element.id.indexOf(parentId) > -1)
                                {
                                    return true;
                                }
                                element = element.parentNode;
                            }
                            return false;
                        }";
               

                rsb = new RadScriptBlock();
                rsb.ID = "scriptBlock";
                rsb.Controls.Add(javaScr);



                Page.ClientScript.RegisterClientScriptBlock(typeof(DenemeWebPart), "aaa", gridscript, true);

                //Page.ClientScript.RegisterClientScriptBlock(typeof(DenemeWebPart), "bbb", xyz, true);

                this.Controls.Add(rsb);
                this.Controls.Add(ralp);
                this.Controls.Add(ram);



                this.Controls.Add(Button1);
                this.Controls.Add(TextBox1);
                this.Controls.Add(grdPendingOrders);
                this.Controls.Add(grdShippedOrders);
                this.Controls.Add(msg);
                this.Controls.Add(hl);


                base.CreateChildControls();
            }







            protected IList<Order> PendingOrders
            {
                get
                {
                    try
                    {
                        object obj = this.Page.Session["PendingOrders"];
                        if (obj == null)
                        {
                            obj = GetOrders();
                            if (obj != null)
                            {
                                this.Page.Session["PendingOrders"] = obj;
                            }
                            else
                            {
                                obj = new List<Order>();
                            }
                        }
                        return (IList<Order>)obj;
                    }
                    catch
                    {
                        this.Page.Session["PendingOrders"] = null;
                    }
                    return new List<Order>();
                }
                set { this.Page.Session["PendingOrders"] = value; }
            }

            protected IList<Order> ShippedOrders
            {
                get
                {
                    try
                    {
                        object obj = this.Page.Session["ShippedOrders"];
                        if (obj == null)
                        {
                            this.Page.Session["ShippedOrders"] = obj = new List<Order>();
                        }
                        return (IList<Order>)obj;
                    }
                    catch
                    {
                        this.Page.Session["ShippedOrders"] = null;
                    }
                    return new List<Order>();
                }
                set { this.Page.Session["ShippedOrders"] = value; }
            }

            protected void grdPendingOrders_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
            {
                grdPendingOrders.DataSource = PendingOrders;
            }

            protected IList<Order> GetOrders()
            {
                IList<Order> results = new List<Order>();

                results.Add(new Order(15, "sdfsdfsd", "dsfdsgfds", DateTime.Now.ToShortDateString()));
                results.Add(new Order(200, "12365487", "flkgjfkjfkjkf", DateTime.Now.ToShortDateString()));
                results.Add(new Order(125, "987456", "ömdmönfönsögnfdg", DateTime.Now.ToShortDateString()));
                results.Add(new Order(153, "sdfsdfsd", "dsfdsgfds", DateTime.Now.ToShortDateString()));
                results.Add(new Order(24400, "12365487", "flkgjfkjfkjkf", DateTime.Now.ToShortDateString()));
                results.Add(new Order(16625, "987456", "ömdmönfönsögnfdg", DateTime.Now.ToShortDateString()));
                results.Add(new Order(1335, "sdfsdfsd", "dsfdsgfds", DateTime.Now.ToShortDateString()));
                results.Add(new Order(26600, "12365487", "flkgjfkjfkjkf", DateTime.Now.ToShortDateString()));
                results.Add(new Order(18825, "987456", "ömdmönfönsögnfdg", DateTime.Now.ToShortDateString()));
                results.Add(new Order(1795, "sdfsdfsd", "dsfdsgfds", DateTime.Now.ToShortDateString()));
                results.Add(new Order(2200, "12365487", "flkgjfkjfkjkf", DateTime.Now.ToShortDateString()));
                results.Add(new Order(16625, "987456", "ömdmönfönsögnfdg", DateTime.Now.ToShortDateString()));
                results.Add(new Order(1885, "sdfsdfsd", "dsfdsgfds", DateTime.Now.ToShortDateString()));
                results.Add(new Order(29900, "12365487", "flkgjfkjfkjkf", DateTime.Now.ToShortDateString()));
                results.Add(new Order(12005, "987456", "ömdmönfönsögnfdg", DateTime.Now.ToShortDateString()));



                return results;
            }

            protected void grdShippedOrders_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
            {
                grdShippedOrders.DataSource = ShippedOrders;
            }

            protected void grdPendingOrders_RowDrop(object sender, GridDragDropEventArgs e)
            {
                if (string.IsNullOrEmpty(e.HtmlElement))
                {
                    if (e.DraggedItems[0].OwnerGridID == grdPendingOrders.ClientID)
                    {
                        // items are drag from pending to shipped grid
                        if ((e.DestDataItem == null && ShippedOrders.Count == 0) ||
                            e.DestDataItem != null && e.DestDataItem.OwnerGridID == grdShippedOrders.ClientID)
                        {
                            IList<Order> shippedOrders = ShippedOrders;
                            IList<Order> pendingOrders = PendingOrders;
                            foreach (GridDataItem draggedItem in e.DraggedItems)
                            {
                                Order tmpOrder = GetOrder(pendingOrders, (int)draggedItem.GetDataKeyValue("OrderId"));

                                if (tmpOrder != null)
                                {
                                    shippedOrders.Add(tmpOrder);
                                    pendingOrders.Remove(tmpOrder);
                                }
                            }

                            ShippedOrders = shippedOrders;
                            PendingOrders = pendingOrders;
                            grdPendingOrders.Rebind();
                            grdShippedOrders.Rebind();
                        }
                        else if (e.DestDataItem != null && e.DestDataItem.OwnerGridID == grdPendingOrders.ClientID)
                        {
                            //reorder items in pending grid
                            IList<Order> pendingOrders = PendingOrders;
                            Order order = GetOrder(pendingOrders, (int)e.DestDataItem.GetDataKeyValue("OrderId"));
                            int destinationIndex = pendingOrders.IndexOf(order);

                            List<Order> ordersToMove = new List<Order>();
                            foreach (GridDataItem draggedItem in e.DraggedItems)
                            {
                                Order tmpOrder = GetOrder(pendingOrders, (int)draggedItem.GetDataKeyValue("OrderId"));
                                if (tmpOrder != null)
                                    ordersToMove.Add(tmpOrder);
                            }

                            foreach (Order orderToMove in ordersToMove)
                            {
                                pendingOrders.Remove(orderToMove);
                                pendingOrders.Insert(destinationIndex, orderToMove);
                            }
                            PendingOrders = pendingOrders;
                            grdPendingOrders.Rebind();
                            e.DestDataItem.Selected = true;
                        }
                    }
                }
            }

            private static Order GetOrder(IEnumerable<Order> ordersToSearchIn, int orderId)
            {
                foreach (Order order in ordersToSearchIn)
                {
                    if (order.OrderID == orderId)
                    {
                        return order;
                    }
                }
                return null;
            }

            protected void grdShippedOrders_RowDrop(object sender, GridDragDropEventArgs e)
            {
                if (!string.IsNullOrEmpty(e.HtmlElement) && e.HtmlElement == "trashCan")
                {
                    IList<Order> shippedOrders = ShippedOrders;
                    bool deleted = false;
                    foreach (GridDataItem draggedItem in e.DraggedItems)
                    {
                        Order tmpOrder = GetOrder(shippedOrders, (int)draggedItem.GetDataKeyValue("OrderId"));

                        if (tmpOrder != null)
                        {
                            shippedOrders.Remove(tmpOrder);
                            deleted = true;
                        }
                    }
                    if (deleted)
                    {
                        msg.Visible = true;
                    }
                    ShippedOrders = shippedOrders;
                    grdShippedOrders.Rebind();
                }
            }

            #region Nested type: Order

            [Serializable]
            protected class Order
            {
                private string _companyName;
                private string _customerId;
                private int _orderId;
                private string _date;

                public Order(int orderId, string customerId, string companyName, string requiredDate)
                {
                    _orderId = orderId;
                    _customerId = customerId;
                    _companyName = companyName;
                    _date = requiredDate;
                }

                public int OrderID
                {
                    get { return _orderId; }
                }

                public string CustomerID
                {
                    get { return _customerId; }
                }

                public string Company
                {
                    get { return _companyName; }
                }

                public string Date
                {
                    get { return _date; }
                }
            }

            #endregion

            protected void Button1_Click(object sender, EventArgs e)
            {
                TextBox1.Text = "yep";
                IList<Order> results = new List<Order>();

                results.Add(new Order(888, "qwerty", "dsfdsgfds", DateTime.Now.ToShortDateString()));
                results.Add(new Order(333, "vbngjhjh", "mmmöklşkş", DateTime.Now.ToShortDateString()));
                results.Add(new Order(0000, "987456", "uıouıoı", DateTime.Now.ToShortDateString()));


                grdPendingOrders.DataSource = results;
                grdPendingOrders.Rebind();
            }




        }
    }



  2. Tarık
    Tarık avatar
    3 posts
    Member since:
    Jul 2008

    Posted 16 Jul 2008 Link to this post

    And also I would like to add that, we are using the free trial version of Radgrid control and if we can successfully implement drag and drop operation between 2 radgrids in the same sharepoint webpart, we will buy a licenced version of product. We searched the web demos and in sharepoint.telerik.com subdomain we have found out a radgrid demo. But the source code was not available with our first time search. Is it possible to see the source code of radgrid demo in sharepoint.telerik.com domain.

    Thanks in advance.

    Tarık KRANDA

  3. Answer
    Rosen
    Admin
    Rosen avatar
    3234 posts

    Posted 17 Jul 2008 Link to this post

    Hello Tarık,

    I have attached a modified version of the WebPart in which is demonstrated a possible way of implementing the drag&drop example under MOSS environment. Please give it a try and see if it helps.

    Note that the scripts a registered with page's type instead of webpart's one.

    Best regards,
    Rosen
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  4. Tarık
    Tarık avatar
    3 posts
    Member since:
    Jul 2008

    Posted 17 Jul 2008 Link to this post

    Hi Rosen,
    I tried the it with appropriate change at script registration, now everything is ok and there is no problem:) Thank you very much for your exact solution and rapid help.

    Yours sincerely,
    Tarık KRANDA


  5. Bob
    Bob avatar
    55 posts
    Member since:
    Apr 2008

    Posted 07 Aug 2008 Link to this post

    Similar issue here.  Once I try to add script for the tree via my webpart code and the RegisterClientScriptBlock a javascript error occurs on the page at load, and the tree becomes unusable. 

    The Error:
    "Error: 'ClientNodeClicked' is undefined."

    Heres the code:

    Protected Sub AddTelerikControls()

    Dim nl As String = Environment.NewLine

    Dim m_RadTreeFolderHierarchy As New Telerik.Web.UI.RadTreeView ' Telerik.WebControls.RadTreeView

    Try

    m_RadTreeFolderHierarchy.LoadContentFile(

    "~/MJComponentSupport/TreeData.xml")

    m_RadTreeFolderHierarchy.CheckBoxes =

    True

    m_RadTreeFolderHierarchy.EnableDragAndDrop =

    True

    'm_RadTreeFolderHierarchy.LoadContentFile("~/Layouts/MJTree/TreeData.xml")

    Catch ex As Exception

    Dim RadTreeNodeRoot As New Telerik.Web.UI.RadTreeNode(_WorkEmail)

    m_RadTreeFolderHierarchy.Nodes.Add(RadTreeNodeRoot)

    RadTreeNodeRoot =

    New Telerik.Web.UI.RadTreeNode(ex.Message)

    m_RadTreeFolderHierarchy.Nodes.Add(RadTreeNodeRoot)

    End Try

     

    ' tree node code

    Dim javaScr As String = "" & nl & nl & _

    " function ClientNodeClicked(sender, eventArgs) " & nl & nl & _

    "{ " & nl & nl & _

    " var node = eventArgs.get_node(); " & nl & nl & _

    " alert('You clicked ' + node.get_text());" & nl & nl & _

    "}" & nl & nl & _

    " function onNodeDragging(sender, args)" & nl & nl & _

    " {" & nl & nl & _

    " var target = args.get_htmlElement(); " & nl & _

    "" & nl & _

    " if(!target) return;" & nl & _

    "" & nl & _

    " if (target.tagName == 'INPUT')" & nl & _

    " { " & nl & _

    " target.style.cursor = 'hand';" & nl & _

    " }" & nl & _

    "" & nl & _

    " var(Grid = isMouseOverGrid(target))" & nl & _

    " If (Grid) Then" & nl & _

    " {" & nl & _

    " grid.style.cursor = 'hand';" & nl & _

    " }" & nl & _

    " }" & nl & _

    "" & nl & _

    " function dropOnHtmlElement(args)" & nl & _

    " { " & nl & _

    " If (droppedOnInput(args)) Then" & nl & _

    " return;" & nl & _

    "" & nl & _

    " If (droppedOnGrid(args)) Then" & nl & _

    " return; " & nl & _

    " }" & nl & _

    "" & nl & _

    " function droppedOnGrid(args)" & nl & _

    " {" & nl & _

    " var target = args.get_htmlElement();" & nl & _

    "" & nl & _

    " While (target)" & nl & _

    " {" & nl & _

    " if(target.id == gridId)" & nl & _

    " {" & nl & _

    " args.set_htmlElement(target);" & nl & _

    " return; " & nl & _

    " }" & nl & _

    "" & nl & _

    " target = target.parentNode;" & nl & _

    " }" & nl & _

    " args.set_cancel(true);" & nl & _

    " }" & nl & _

    "" & nl & _

    " function droppedOnInput(args)" & nl & _

    " {" & nl & _

    " var target = args.get_htmlElement();" & nl & _

    " if (target.tagName == 'INPUT')" & nl & _

    " {" & nl & _

    " target.style.cursor = 'default';" & nl & _

    " target.value = args.get_sourceNode().get_text(); " & nl & _

    " args.set_cancel(true);" & nl & _

    " return true;" & nl & _

    " } " & nl & _

    " }" & nl & _

    "" & nl & _

    " function dropOnTree(args)" & nl & _

    " {" & nl & _

    " var text = '';" & nl & _

    "" & nl & _

    "If (args.get_sourceNodes().length) Then" & nl & _

    " { " & nl & _

    " var i; " & nl & _

    " for(i=0; i < args.get_sourceNodes().length; i++) " & nl & _

    " { " & nl & _

    " var node = args.get_sourceNodes()[i];" & nl & _

    " text = text + ', ' +node.get_text();" & nl & _

    " }" & nl & _

    " }" & nl & _

    "}" & nl & _

    "" & nl & _

    " function clientSideEdit(sender, args)" & nl & _

    "{" & nl & _

    " var destinationNode = args.get_destNode(); " & nl & _

    "" & nl & _

    " If (destinationNode) Then" & nl & _

    " { " & nl & _

    " var firstTreeView = $find('RadTreeView1');" & nl & _

    " var secondTreeView = $find('RadTreeView2');" & nl & _

    "" & nl & _

    " firstTreeView.trackChanges();" & nl & _

    " secondTreeView.trackChanges();" & nl & _

    " var sourceNodes = args.get_sourceNodes();" & nl & _

    "for (var i = 0; i < sourceNodes.length; i++)" & nl & _

    "{" & nl & _

    " var sourceNode = sourceNodes[i];" & nl & _

    " sourceNode.get_parent().get_nodes().remove(sourceNode); " & nl & _

    "" & nl & _

    " if(args.get_dropPosition() == 'over') destinationNode.get_nodes().add(sourceNode); " & nl & _

    " if(args.get_dropPosition() == 'above') insertBefore(destinationNode, sourceNode);" & nl & _

    " if(args.get_dropPosition() == 'below') insertAfter(destinationNode, sourceNode);" & nl & _

    "}" & nl & _

    "destinationNode.set_expanded(true);" & nl & _

    "firstTreeView.commitChanges();" & nl & _

    "secondTreeView.commitChanges();" & nl & _

    "}" & nl & _

    "}" & nl & _

    " function insertBefore(destinationNode, sourceNode)" & nl & _

    " { " & nl & _

    " var destinationParent = destinationNode.get_parent();" & nl & _

    " var index = destinationParent.get_nodes().indexOf(destinationNode);" & nl & _

    " destinationParent.get_nodes().insert(index, sourceNode);" & nl & _

    " }" & nl & _

    "" & nl & _

    " function insertAfter(destinationNode, sourceNode)" & nl & _

    " {" & nl & _

    " var destinationParent = destinationNode.get_parent();" & nl & _

    " var index = destinationParent.get_nodes().indexOf(destinationNode);" & nl & _

    " destinationParent.get_nodes().insert(index+1, sourceNode);" & nl & _

    " } " & nl & _

    " function onNodeDropping(sender, args)" & nl & _

    " { " & nl & _

    " var dest = args.get_destNode();" & nl & _

    " If (dest) Then" & nl & _

    " { " & nl & _

    " var clientSide = document.getElementById('ChbClientSide').checked;" & nl & _

    "" & nl & _

    " If (clientSide) Then" & nl & _

    " {" & nl & _

    " clientSideEdit(sender, args); " & nl & _

    " args.set_cancel(true);" & nl & _

    " return;" & nl & _

    " }" & nl & _

    "" & nl & _

    " dropOnTree(args);" & nl & _

    " }" & nl & _

    " Else" & nl & _

    " { " & nl & _

    " dropOnHtmlElement(args);" & nl & _

    " }" & nl & _

    " }"

     

    m_RadTreeFolderHierarchy.OnClientNodeClicked =

    "ClientNodeClicked"

    Me.Controls.Add(m_RadTreeFolderHierarchy)

    ScriptManager.RegisterClientScriptBlock(Page,

    GetType(Page), "aaa", javaScr, True)

     

    End Sub

  6. Karthik
    Karthik avatar
    3 posts
    Member since:
    Jun 2009

    Posted 18 Jun 2009 Link to this post

    Hi,
    Currently we are using Ajax enabled RadTreeView, Everything working fine what expect, However I am not able to get OnClientNodeClicked  function, its showing the error message like "OnClientNodeClicked  is undefined".I am using TreeView Control into my SharePoint Cumtom Fieldcontrol.

    <%@ Control Language="C#" %>

    <%@ Assembly Name="IndiaCustomControl, Version=1.0.0.0, Culture=neutral, PublicKeyToken=bee3c861d84fd9a0" %>

    <%@ Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WebControls" %>
    <%@ Register Assembly="Telerik.Web.UI, Version=2008.3.1314.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>   
     <%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"   Namespace="System.Web.UI" TagPrefix="asp" %>
     
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
                
           function ClientNodeClicked(sender, eventArgs)
    {
        
      var node = eventArgs.get_node();
           var s = node.get_text();
           var currentObject = node.get_parent();
           var  i=0;
           while (currentObject != null)      
           {        
             if (currentObject.get_parent() != null)
             {
               s = currentObject.get_text()+"/"+s;
             }
             currentObject = currentObject.get_parent();
             i = i+1;
           }      
          if(i==4)
          {
           // document.getElementById('lblText').innerHTML = s;
           alert(s);
          }
          else
          {
           // document.getElementById('lblText').innerHTML = "";
           alert(s);
          }

    }
       </script>
       </telerik:RadCodeBlock>  
    <SharePoint:RenderingTemplate Id="IndiaCustomFieldRendering" runat="server">

        <Template>   

            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">   
            </telerik:RadAjaxManager>
           
           <telerik:RadTreeView ID ="radTreeView" runat ="server" OnClientNodeClicked ="ClientNodeClicked">
            <Nodes>
                <telerik:RadTreeNode Text ="karthik"></telerik:RadTreeNode>
                <telerik:RadTreeNode Text ="keyan"></telerik:RadTreeNode>
            </Nodes>          
            </telerik:RadTreeView>
           
            <asp:TextBox runat="server" ID="txtFirstName" />
            <asp:TextBox runat="server" ID="txtLastName" />
            <asp:Button runat ="server" ID ="Btn" Text ="Muruga" />
                 </Template>

    </SharePoint:RenderingTemplate>

  7. Bob
    Bob avatar
    55 posts
    Member since:
    Apr 2008

    Posted 19 Jun 2009 Link to this post

    Karthik,  Are you getting an error on the page?  Also, are you injecting javascript into the page for your events, or are you using         the AddHandler syntax (ie   AddHandler m_RadTreeFolderHierarchy.NodeClick, AddressOf treeView_NodeClick)?
  8. Karthik
    Karthik avatar
    3 posts
    Member since:
    Jun 2009

    Posted 19 Jun 2009 Link to this post

    Hi Bob,
    Thanks for your response, now this issue is resolved. I movedthe <script type="text/javascript">...</script> block into inside the <template> tag. now everything is working fine. Thank you!!!!- Karhtik


    <%@ Control Language="C#" %>

    <%@ Assembly Name="IndiaCustomControl, Version=1.0.0.0, Culture=neutral, PublicKeyToken=bee3c861d84fd9a0" %>

    <%@ Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" Namespace="Microsoft.SharePoint.WebControls" %>
    <%@ Register Assembly="Telerik.Web.UI, Version=2008.3.1314.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>   
     <%@ Register Assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"   Namespace="System.Web.UI" TagPrefix="asp" %>
     

    <SharePoint:RenderingTemplate Id="IndiaCustomFieldRendering" runat="server">

        <Template>   

            <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">   
            </telerik:RadAjaxManager>
           
           <telerik:RadTreeView ID ="radTreeView" runat ="server" OnClientNodeClicked ="ClientNodeClicked">
            <Nodes>
                <telerik:RadTreeNode Text ="karthik"></telerik:RadTreeNode>
                <telerik:RadTreeNode Text ="keyan"></telerik:RadTreeNode>
            </Nodes>          
            </telerik:RadTreeView>
           
            <asp:TextBox runat="server" ID="txtFirstName" />
            <asp:TextBox runat="server" ID="txtLastName" />
            <asp:Button runat ="server" ID ="Btn" Text ="Muruga" />

    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
                
           function ClientNodeClicked(sender, eventArgs)
    {
        
      var node = eventArgs.get_node();
           var s = node.get_text();
           var currentObject = node.get_parent();
           var  i=0;
           while (currentObject != null)      
           {        
             if (currentObject.get_parent() != null)
             {
               s = currentObject.get_text()+"/"+s;
             }
             currentObject = currentObject.get_parent();
             i = i+1;
           }      
          if(i==4)
          {
           // document.getElementById('lblText').innerHTML = s;
           alert(s);
          }
          else
          {
           // document.getElementById('lblText').innerHTML = "";
           alert(s);
          }

    }
       </script>
       </telerik:RadCodeBlock>
      
                 </Template>

    </SharePoint:RenderingTemplate>

Back to Top