Aug 24, 2010, 9:26 PM
[CLOSED] TreePanel refresh in codebehind can't handle many icons
I have a TreePanel like the sample https://examples1.ext.net/#/TreePane...h_Static_Tree/ except that I want to use different icons. I found that everytime I refresh, I have to reregister the icons or they don't show up. This seems to be too much for the control to handle. If you run the code below and refresh several times, at least four for me, there is an Invalid procedure call or argument in ext.axd.
Please let me know what I am doing wrong. Is there a better way to use icons in the TreePanel?
Thanks.
-Steve
Please let me know what I am doing wrong. Is there a better way to use icons in the TreePanel?
Thanks.
-Steve
<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack && !X.IsAjaxRequest)
{
this.BuildTree(TreePanel1.Root);
}
}
private Ext.Net.TreeNodeCollection BuildTree(Ext.Net.TreeNodeCollection nodes)
{
if (nodes == null)
{
nodes = new Ext.Net.TreeNodeCollection();
}
ResourceManager1.RegisterIcon(Icon.StopBlue);
ResourceManager1.RegisterIcon(Icon.BulletTick);
ResourceManager1.RegisterIcon(Icon.GroupGo);
ResourceManager1.RegisterIcon(Icon.FlowerDaisy);
ResourceManager1.RegisterIcon(Icon.Cog);
ResourceManager1.RegisterIcon(Icon.Report);
ResourceManager1.RegisterIcon(Icon.Clipboard);
Ext.Net.TreeNode root = new Ext.Net.TreeNode();
root.Text = "Root";
nodes.Add(root);
string prefix = DateTime.Now.Second + ": This is text for the menu item";
for (int i = 0; i < 10; i++)
{
Ext.Net.TreeNode node = new Ext.Net.TreeNode("Top");
root.Nodes.Add(node);
addNode(node, prefix + "1", Icon.StopBlue);
addNode(node, prefix + "2", Icon.BulletTick);
addNode(node, prefix + "3", Icon.GroupGo);
addNode(node, prefix + "4", Icon.FlowerDaisy);
addNode(node, prefix + "5", Icon.Cog);
addNode(node, prefix + "6", Icon.Report);
addNode(node, prefix + "7", Icon.Clipboard);
addNode(node, prefix + "8", Icon.Cog);
addNode(node, prefix + "9", Icon.GroupGo);
addNode(node, prefix + "10", Icon.BulletTick);
}
return nodes;
}
private void addNode(Ext.Net.TreeNode root, string nodeText, Ext.Net.Icon icon)
{
root.Nodes.Add(new Ext.Net.TreeNode(nodeText,icon));
}
[DirectMethod]
public string RefreshMenu()
{
Ext.Net.TreeNodeCollection nodes = this.BuildTree(null);
return nodes.ToJson();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head2" runat="server">
<title>SiteMap - Ext.NET Examples</title>
</head>
<body>
<form id="Form1" runat="server">
<script type="text/javascript">
var refreshTree = function(tree) {
Ext.net.DirectMethods.RefreshMenu({
success: function(result) {
var nodes = eval(result);
if (nodes.length > 0) {
tree.initChildren(nodes);
}
else {
tree.getRootNode().removeChildren();
}
}
});
}
</script>
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:TabPanel runat="server">
<Items>
<ext:Panel Title="The One" runat="server">
<Items>
<ext:TreePanel
ID="TreePanel1"
runat="server"
Icon="Anchor"
Title="Tree"
AutoScroll="true"
Width="250"
Collapsed="False"
CollapseFirst="True"
HideParent="False"
RootVisible="False"
BodyStyle="padding-left:10px">
<Tools>
<ext:Tool Type="Refresh" Qtip="Refresh" Handler="refreshTree(#{TreePanel1});" />
</Tools>
</ext:TreePanel>
</Items>
</ext:Panel>
<ext:Panel Title="The Other" runat="server">
<Items>
</Items>
</ext:Panel>
</Items>
</ext:TabPanel>
</form>
</body>
</html>
Last edited by Daniil; Sep 13, 2010 at 5:40 AM.
Reason: [CLOSED]