Template Content Included on Edit When Node Text is Empty

8 posts, 0 answers
  1. Marbry
    Marbry avatar
    123 posts
    Member since:
    Aug 2012

    Posted 22 Jul 2011 Link to this post

    I have a number of templates applied to provide property labels on certain nodes like below.  So that even when Property 2 for instance has no value, it's still labeled as such by the template.

    Item1
       Property 1: Property1Value
       Property 2:
    Item 2

    This works fine when editing one of the property nodes that already has a value like Property 1.  But when editing an empty node like Property 2, instead of just showing a blank edit box, you would see the label in there like "Property 2:  ".  Then it passes the whole thing as the text in the event args to the NodeEdit handler rather than just the entered value.  So you get "Property 2: Prop2value" rather than just "Prop2Value".

    I've tried it like below and also breaking out the wrapping tag for the value into a second label and setting the DataBinding handler on that.  I get the same result either way.  Am I missing something or is this a bug?


    public class Property2Template : ITemplate
    {
        public void InstantiateIn(Control container)
        {
            Label label1 = new Label();
            RadTreeNode node = (RadTreeNode)container;
            label1.Text = "Property 2: <span class=\"PropertyValue\">" + node.Text + "</span>";
            label1.CssClass = "PropertyLabel";
            container.Controls.Add(label1);
        }
    }

    also

    public class Property2Template : ITemplate
    {
        public void InstantiateIn(Control container)
        {
            Label label1 = new Label();
            Label label2 = new Label();
            RadTreeNode node = (RadTreeNode)container;
            label1.Text = "Property 2: ";
            label1.CssClass = "PropertyLabel";
            label2.Text = node.Text;
            label2.CssClass = "PropertyValue";
            label2.DataBinding += new EventHandler(label2_DataBinding);
            container.Controls.Add(label1);
            container.Controls.Add(label2);
        }
        public void label2_DataBinding(object sender, EventArgs e)
        {
            Label target = (Label)sender;
            RadTreeNode node = (RadTreeNode)target.BindingContainer;
            string nodeText = (string)DataBinder.Eval(node, "Text");
            target.Text = nodeText;
        }
    }
  2. Plamen
    Admin
    Plamen avatar
    3040 posts

    Posted 26 Jul 2011 Link to this post

    Hi Marbry,

    You may try to change the NodeEdit event like this:
    protected void RadTreeView1_NodeEdit(object sender, RadTreeNodeEditEventArgs e)
       {
           RadTreeNode nodeEdited = e.Node;
           string newText =" "+e.Text;
           nodeEdited.Text = newText;
            
           RadTreeView1.DataBind();
       }

    Hope this will help you.

    Kind regards, Plamen Zdravkov
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  3. Marbry
    Marbry avatar
    123 posts
    Member since:
    Aug 2012

    Posted 26 Jul 2011 Link to this post

    Hi Plamen, I'm afraid that doesn't really address the issue, just adds a space onto the beginning of the title + entered text.

    So after it executes this,
        string newText =" "+e.Text;

    The newText variable value is just " Property 2:  PropValue2" with that extra leading space, as opposed to just "PropValue2" which it should be.

    It appears that the control is substituting the first innerText value it can find in the template content when that is empty for what shoud be the container for the actual node text.
  4. Plamen
    Admin
    Plamen avatar
    3040 posts

    Posted 28 Jul 2011 Link to this post

    Hello Marbry,

    Here is the project that I tested locally and didn't notice any odd behavior.

    Would you please explain what exactly is the issue or try to isolate the problem in a sample project and send it to us via a support ticket?

    Regards,
    Plamen Zdravkov
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  5. Marbry
    Marbry avatar
    123 posts
    Member since:
    Aug 2012

    Posted 28 Jul 2011 Link to this post

    Thank you for the response Plamen, but your test project exhibited the exact same behavior I described.

    Open the project and it starts out with,

    Property2: root1
    Property2:

    ...as the last two nodes.  If you double click to edit the last node and type in "newvalue" without manually deleting the "Property2: " that is displayed in the edit box, then move off the node, the last node will now display "Property2: Property2: newvalue".

    I am noticing that it only seems to occur on the first edit.  For instance if you go back and edit the same node again, but delete all the text, when you return to edit again it will not display the label text even though there is no node text.
  6. Plamen
    Admin
    Plamen avatar
    3040 posts

    Posted 29 Jul 2011 Link to this post

    Hi Marbry,

    I noticed the problem and it really looks like an unusual behaviour. It seems that when the "label2" is empty the edit mode ignores it so we must not leave it empty. That is why the workaround is when we create it we set one space for Text and when we change it we do the same. Here is the change I made in the project that I sent you that worked for me:
    protected void Page_Load(object sender, EventArgs e)
       {
           if (!Page.IsPostBack)
           {
               RadTreeView1.Nodes.Add(new RadTreeNode("root1","AAAAAA")); RadTreeView1.Nodes.Add(new RadTreeNode(" "));
           }
     
           RadTreeView1.DataBind();
       }

    All the best,
    Plamen Zdravkov
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  7. Marbry
    Marbry avatar
    123 posts
    Member since:
    Aug 2012

    Posted 29 Jul 2011 Link to this post

    Thanks Plamen, I think that is going to work.  I was thinking about that last night and started wondering if it might be a similar issue to table cells not getting rendered when empty unless you dump a non-breaking space in there.

    I don't know what your internal process is for posting suggested fixes, but it would be nice if this could be handled transparetly.  It's easy enough in my implementation to just trim all the edit values coming back, but if someone was trying to preserve user entered leading spaces for some reason it might be an issue.
  8. Plamen
    Admin
    Plamen avatar
    3040 posts

    Posted 01 Aug 2011 Link to this post

    Hi Marbry,

    Thanks for the feedback. We will consider your suggestions.

    Greetings,
    Plamen Zdravkov
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Back to Top