I would like to know how to html encode nodes in a asp.net treeview control? I have a requirement that requires the nodes to have items that accepts “<” “>” symbols.
The code sample below is what I’m currently using as a treenode.
public class SampleTreeNode : TreeNode
{
public SampleTreeNode(string text, string value)
: base(HttpUtility.HtmlEncode(text), value)
{
}
}
The problem with this is that when I put it a node with text “”. It displays the text as “<Test>” instead of “”. I’m not sure if this is the best place to put the encode command.
Use HttpContex.Current.Server.HtmlEncode and HttpContex.Current.Server.HtmlDecode