PDA

View Full Version : [CLOSED] TreePanel is not refresh in button click



canusr1
Jul 24, 2013, 3:34 AM
Hi,

TreePanel is not show when I bind TreePanel in button click event.
But when I call this in Page Load TreePanel is show.
How to refresh TreePanle dynamically from code behind.



<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script runat="server">
private Ext.Net.NodeCollection BuildTree(Ext.Net.NodeCollection nodes)
{
if (nodes == null)
{
nodes = new Ext.Net.NodeCollection();
}

Ext.Net.Node root = new Ext.Net.Node();
root.Text = "Root";
root.Expanded = true;
nodes.Add(root);

string prefix = DateTime.Now.Second + "_";

for (int i = 0; i < 10; i++)
{
Ext.Net.Node node = new Ext.Net.Node();
node.Text = prefix + i;
node.Leaf = true;
node.Expanded = true;
root.Children.Add(node);
}

return nodes;
}

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack && !X.IsAjaxRequest)
{
//this.BuildTree(TreePanel1.Root); // tree is show if bind in page load method
}
}
protected void Button1_DirectClick(object sender, DirectEventArgs e)
{
this.BuildTree(TreePanel1.Root); // not showing if i bind tree panel in button click event
}
</script>
<!DOCTYPE html>
<html>
<head runat="server">
<title></title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<ext:Button ID="Button1" runat="server" Text="Load TreePanel" >
<DirectEvents>
<Click OnEvent="Button1_DirectClick"></Click>
</DirectEvents>
</ext:Button>
<ext:TreePanel
ID="TreePanel1"
runat="server"
Title="Tree"
Width="300"
Height="450"
Border="false"
>
</ext:TreePanel>
</form>
</body>
</html>

Daniil
Jul 24, 2013, 5:49 AM
Hi @canusr1,

Please see the example.
http://examples2.ext.net/#/TreePanel/Basic/Refresh_Static_Tree/

anwichmann
Dec 20, 2015, 10:56 AM
How to refresh the Tree from code-behind in direct event (no refresh button on client side!)


this.ArticleTree.Root.Clear();

var articleNode = new Node();
articleNode.Text = "Root";
this.LoadArticles(articleNode.Children);
this.ArticleTree.Root.Add(articleNode);

does not work.

Is there any way to let the Tree reload the nodes from the store?

Daniil
Dec 21, 2015, 10:03 AM
You can try to call this at the end:

this.ArticleTree.ReRender();

anwichmann
Dec 22, 2015, 8:54 AM
Thanks! It is working now.