This is a migrated thread and some comments may be shown as answers.

[Solved] HTML encoding for RadTreeNode.Text fails

3 Answers 287 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Pavel
Top achievements
Rank 1
Pavel asked on 27 Aug 2009, 08:45 AM
Hello

I use RadTreeView with load-on-demand feature (ServerSideCallback). When a node is expanded I create child nodes and do HtmlEncode for its' texts. I see "<input>" text as "<input>" and that's OK. But when I click any child node (I have server-side Click handler that actually do not change any nodes) all "<input>" nodes become text boxes!

I guess it's a bug. Could you give me some workaround?
Thanks.

3 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 31 Aug 2009, 08:28 AM
Hello Pavel,

Actually this is expected behavior of  RadTreeView nodes with "ServerSideCallBack" ExpandMode. I suggest you set ExpandMode to ServerSide and wrap the treeview in RadAjaxPanel in order to avoid reloading of the whole page.

All the best,
Yana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Mark
Top achievements
Rank 1
answered on 11 Feb 2010, 10:15 PM
I'm not sure how you can say that this issue is expected behavior. If the first presentation of the tree nodes shows the htmlEncoded text correctly, but the a postback someplace on the re-renders the already-expanded nodes, but not htmlEncoded now, that seems to me to be a bug.

I am experiencing this same issue right now... I have a subnode named "x + 5 > 7". It displays fine the first time it's parent is expanded, and the htmlEncoded text is added as a subnode. However, after pressing a postback button on the page, the treeview gets re-rendered with that node showing as "x + 5 >"... the "7" part is gone.

The workaround, by the way, is not an option for me as during the click event of the postback button, I uncheck some of the treeview nodes based on business logic.

Please... a workaround, at least, is need here.
0
Pavel
Top achievements
Rank 1
answered on 12 Feb 2010, 07:46 AM
Hi Mark,

The idea is to encode nodes created in NodeExpand handler again during the following postback. To do it you need
1) save a key of expanded  node (I use Node.Value property) in a list stored in the session and 2) do encoding in Load handler.
Here is a fragment of my Load handler:
if (!this.IsPostBack) 
    Session["ExpandedNodeValues"] = new List<string>(); 
else if (!this.Page.IsCallback) 
    List<string> nodeValues = (List<string>)Session["ExpandedNodeValues"]; 
    foreach (string value in nodeValues.ToArray()) 
    { 
        // encode all children of the node with specified value 
        var nodes = FindAllNodes(x => x.ParentNode != null && x.ParentNode.Value == value); 
        foreach (RadTreeNode node in nodes) 
        { 
            node.Text = Server.HtmlEncode(node.Text); 
        } 
    } 
    nodeValues.Clear(); 
 


Tags
TreeView
Asked by
Pavel
Top achievements
Rank 1
Answers by
Yana
Telerik team
Mark
Top achievements
Rank 1
Pavel
Top achievements
Rank 1
Share this question
or