Node reset to initial edit text on node click unless refreshed

5 posts, 0 answers
  1. Chameleoki
    Chameleoki avatar
    28 posts
    Member since:
    Dec 2005

    Posted 14 Mar 2011 Link to this post

    I have a TreeView where clicking a context menu will add a new node and put it into edit view (as per the many examples on here). I have the inital new node text as "default", just like the example.  If I press the Enter key after editing, it works as expected and it is renamed and saved.

    But if instead, during edit mode, I click on another node (or even the same node), it DOES save the changes behind the scenes but the node text resets back to the initial text of "default" until the entire page is refreshed (or another TreeView databind).

    I have tried everything I can think of but I can't tell at what point it's getting saved verses when it's running the nodeclick event.

    Any ideas?
  2. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 17 Mar 2011 Link to this post

    Hello Chameleoki,

    Could you, please, post an example of the current implementation of your TreeView? I would like to see how does the node save the new text in the background. Knowing this I should be able to suggest a solution for the problem.


    Regards,
    Nikolay Tsenkov
    the Telerik team
  3. Chameleoki
    Chameleoki avatar
    28 posts
    Member since:
    Dec 2005

    Posted 17 Mar 2011 Link to this post

    Here's the pertinent code.  I do have RadAjaxManager on the page, and a grid that is updated when a node is clicked.  Thank you.

    private
    void AddNode(RadTreeViewContextMenuEventArgs e, RadTreeNode n)
            {
                RadTreeNode newNode = new RadTreeNode();
                newNode.Value = System.Guid.NewGuid().ToString();
                newNode.Text = "default";
                newNode.AllowEdit = true;
                newNode.Value = "0";
                newNode.ExpandedImageUrl = "~/Images/Folder.png";
                newNode.ImageUrl = "~/Images/Folder-close.png";
                newNode.SelectedImageUrl = "~/Images/Folder.png";
                newNode.HoveredImageUrl = "~/Images/Folder.png";
                newNode.Attributes.Add("IsLocked", "N");
                newNode.Attributes.Add("IsArchived", "N");
      
                n.Nodes.Add(newNode);
                string strScript = "Sys.Application.add_load(function(){ HighlightNode(\"" + newNode.Value + "\")})";
                string script = "HighlightNode(\"" + newNode.Value+ "\")";
                this.RadAjaxManager1.ResponseScripts.Add(script);
                lblFolderStatus.Text = "";
                rgFiles.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
                RadMenu1.FindItemByValue("Checkin").Visible = true;
                RadMenu1.FindItemByValue("Checkout").Visible = true;
            }
      
    protected void RadTreeView1_ContextMenuItemClick(object sender, RadTreeViewContextMenuEventArgs e)
            {
                SharedFolder folder = new SharedFolder(int.Parse(e.Node.Value));
                UserInfo objUserInfo = UserSecurity.GetUserInfo();
                if (!string.IsNullOrEmpty(folder.StatusMessage))
                {
                    RadAjaxManager1.Alert("Error Retrieving Folder.  Error:" + folder.StatusMessage);
                }
                else
                {
                    switch (e.MenuItem.Value.ToString().ToUpper())
                    {
                        case "ADD":
                            AddNode(e, e.Node);
                            break;
                        ........
                    rgFiles.Rebind();
                   }
                }
            }
      
    protected void RadTreeView1_NodeEdit(object sender, RadTreeNodeEditEventArgs e)
            {
                UserInfo objUserInfo = UserSecurity.GetUserInfo();
                RadTreeNode edited = e.Node;
                edited.Text = e.Text.ToString();
                SharedFolder folder;
                if (edited.Value == "0")
                {
                    folder = new SharedFolder();
                    folder.FolderName = edited.Text;
                    folder.ParentFolderID = int.Parse(e.Node.ParentNode.Value);
                    folder.Save();
                    if (!string.IsNullOrEmpty(folder.StatusMessage))
                    {
                        RadAjaxManager1.Alert("Error Saving Folder.  Error:" + folder.StatusMessage);
                    }
                    else
                    {
                        e.Node.Value = folder.ID.ToString();
                        e.Node.Text = folder.FolderName;
                        objUserInfo.RefreshFolders();
                        //RadTreeView1.DataBind();
                        RadTreeView1.FindNodeByValue(folder.ID.ToString()).Selected = true;
                        rgFiles.Rebind();
                    }
                }
                else
                {
                    folder = new SharedFolder(int.Parse(edited.Value));
                    folder.FolderName = edited.Text;
                    folder.Save();
                    if (!string.IsNullOrEmpty(folder.StatusMessage))
                    {
                        RadAjaxManager1.Alert("Error Saving Folder.  Error:" + folder.StatusMessage);
                    }
                    else
                    {
                        string selectedValue = edited.Value;
                        //RadTreeView1.DataBind();
                        //RadTreeView1.FindNodeByValue(selectedValue).Selected = true;
                        objUserInfo.RefreshFolders();
                        rgFiles.Rebind();
                    }
                }
            
      
    protected void RadTreeView1_NodeClick(object sender, RadTreeNodeEventArgs e)
            {
                UserInfo objUserInfo = UserSecurity.GetUserInfo();
               
                if (e.Node.Attributes["CanWrite"] == "N")
                {
                    lblFolderStatus.Text = "<span class='FolderWarning'>Note: You have read only permissions to this folder.</span>";
                    rgFiles.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None;
                    RadMenu1.FindItemByValue("Checkin").Visible = false;
                    RadMenu1.FindItemByValue("Checkout").Visible = false;
                }
                else if ((e.Node.Attributes["IsLocked"] == "Y") && (objUserInfo.UserType != "Project Admin") && (objUserInfo.UserType != "Site Admin"))
                {
                    lblFolderStatus.Text = "<span class='FolderWarning'>Note: This folder has been locked by an administrator.</span>";
                    rgFiles.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.None;
                    RadMenu1.FindItemByValue("Checkin").Visible = false;
                    RadMenu1.FindItemByValue("Checkout").Visible = false;
                }
                else
                {
                    lblFolderStatus.Text = "";
                    rgFiles.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
                    RadMenu1.FindItemByValue("Checkin").Visible = true;
                    RadMenu1.FindItemByValue("Checkout").Visible = true;
                }
                rgFiles.DataBind();
                btnDownloadFile.NavigateUrl = "~/DownloadZippedFolder.aspx?fid=" + e.Node.Value + "&sub=false";
            }
  4. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 23 Mar 2011 Link to this post

    Hi Chameleoki,

    I have tested the scenario and it didn't reproduce at my end:
     - Markup:
    <telerik:RadTreeView runat="server" ID="RadTreeView1" AllowNodeEditing="true"
            onnodeclick="RadTreeView1_NodeClick" onnodeedit="RadTreeView1_NodeEdit">
        <Nodes>
            <telerik:RadTreeNode Text="Node1" />
            <telerik:RadTreeNode Text="Node1" />
            <telerik:RadTreeNode Text="Node1" />
        </Nodes>
    </telerik:RadTreeView>
     - Code-behind:
    protected void RadTreeView1_NodeClick(object sender, RadTreeNodeEventArgs e)
    {
     
    }
    protected void RadTreeView1_NodeEdit(object sender, RadTreeNodeEditEventArgs e)
    {
        e.Node.Text = e.Text;
    }
    (I made a NodeClick handler in order to check if the NodeClick is being raised in the scenario, but it isn't - you can check this using my sample)

    Please, step through the handler of NodeEdit using the debugger and check for a problem in the algorithm that runs.
     

    Regards,
    Nikolay Tsenkov
    the Telerik team
  5. Chameleoki
    Chameleoki avatar
    28 posts
    Member since:
    Dec 2005

    Posted 23 Mar 2011 Link to this post

    Thank you for your looking into this.  You gave me an idea, and it worked.

    The solution was to increase the RequestQueue size on the RadAjaxManager.  I guess with all of the updates on a click of the node, the editing, the refreshing of the grid and labels on the clicking of a node and such, it needed a bigger queue.
Back to Top