The old node Text returns back after editing

2 posts, 0 answers
  1. shootermv
    shootermv avatar
    8 posts
    Member since:
    Jul 2010

    Posted 01 Nov 2010 Link to this post

    The scenario :
    My customer wants the tree node text to be edited after some button the page clicked. The scenario is as follows:
    1 button clicked
    2 selected node in tree became editable (displayed inside textbox)
    3 after losing focus the changes are saved

    My Code :
    When i populate the tree nodes i set the

    AllowEdit property to false - to prevent node became editable when clicked.
    in the button_Click eventhandler i put call to

     

    startNodeInEditMode function

     

    as in the following code:

    public void startNodeInEditMode(string nodeValue)
    {
                     
        string js = "Sys.Application.add_load(editNode); function editNode(){ ";
        js += "var tree = $find(\"" + RadTreeView1.ClientID + "\");";
        js += "var node = tree.get_selectedNode();";
        js += "if (node) node.startEdit();";
        js += "Sys.Application.remove_load(editNode);};";
        RadScriptManager.RegisterStartupScript(Page, Page.GetType(), "nodeEdit", js, true);           
    }
    protected void RadTreeView1_NodeEdit(object sender, RadTreeNodeEditEventArgs e)
    {

         e.Node.Text = e.Text;


    The Problem :
    The changed  text of the node returns back to old version of text (the changes suddenly disappear after few seconds and old text appear)
    Althougt i see that changes are saved in db inside the RadTreeView1_NodeEdit function.


    Please help








  2. shootermv
    shootermv avatar
    8 posts
    Member since:
    Jul 2010

    Posted 02 Nov 2010 Link to this post

    Seems i've solved my own problem...
    For some who interested to read my solution:
    I noticed that old  node text "comes back" only if after editing the node-text user clicking on the same node (if user clicked somewhere else or lose focus - the changes stays)


    After look inside RadTreeView1_NodeClick method i find:
    that althought  inside preceding  function RadTreeView1_NodeEdit node text was replaced by new version, in the RadTreeView1_NodeClick ,e.Node.Text  value remains the old version value (why??? may be bug?)

    My work around:

     

    public void startNodeInEditMode(string nodeValue)
    {
        //This code is to prevent old Text value
        //of resently edited node to return back 
        //in response of selected node click (telerik bug)
        Session["oldText"] = RadTreeView1.SelectedNode.Text;
          
        string js = "Sys.Application.add_load(editNode); function editNode(){ ";
        js += "var tree = $find(\"" + RadTreeView1.ClientID + "\");";
        js += "var node = tree.get_selectedNode();"
        js += "if (node) node.startEdit();";
        js += "Sys.Application.remove_load(editNode);};";
        RadScriptManager.RegisterStartupScript(Page, Page.GetType(), "nodeEdit", js, true);
    }
    protected void RadTreeView1_NodeEdit(object sender, RadTreeNodeEditEventArgs e)
    {
        //This code is to prevent old Text value
        //of resently edited node to return back 
        //in response of selected node click (telerik bug)
        Session["nodeValue"] = e.Node.Value;
        Session["nodeTextNew"] = e.Text;  
          
          
        e.Node.Text = e.Text;
        //Save to DB
        }
    protected void RadTreeView1_NodeClick(object sender, RadTreeNodeEventArgs e)
    {
        //This code is to prevent old Text value
        //of resently edited node to return back 
        //in response of selected node click (telerik bug)
        if (Session["oldText"] != null)
        {
            if (Session["oldText"].ToString() == e.Node.Text && e.Node.Value == Session["nodeValue"].ToString())
            {
                e.Node.Text = Session["nodeTextNew"].ToString();
                Session.Remove("nodeTextNew");
                Session.Remove("oldText");
            }
        }
    May be it is not the best solution, but it works.
    If you found something more jently - please let me know... 

     

     

      

     


Back to Top