PDA

View Full Version : [CLOSED] Add tab from TreePanel builded in code behind



Antonio09
Jul 20, 2012, 7:53 PM

Daniil
Jul 20, 2012, 9:44 PM
Hi,

Welcome to Ext.NET!

There are several issues.

1. The default Namespace is "App". So, you should use

App.TabPanel1
or

#{TabPanel1}

2. I don't think you should use Href, because it creates an anchor tag with that href. So, the link will be opened when a user clicks a node. I would use an additional field, for example, "url".

3. You should worry about the tabs ids. With all your ItemClick variations there will be just "idopc" for any node. I would use an additional field as well. Though in my example I used just "text" for simplifying.

Example

<%@ Page Language="C#" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
this.TreePanel1.Listeners.ItemClick.Handler = "addTab(App.TabPanel1, record);";
}
</script>

<!DOCTYPE />

<html>
<head runat="server">
<title>Ext.NET v2 Example</title>

<script type="text/javascript">
var addTab = function (tabPanel, record) {
var text = record.data.text,
tab = tabPanel.getComponent(text);

if (!tab) {
tab = tabPanel.add({
id : text,
title : text,
closable : true,
loader : {
url : record.data.url,
renderer : "frame",
loadMask : {
showMask : true,
msg : "Loading " + text + "..."
}
}
});
}
tabPanel.setActiveTab(tab);
};
</script>
</head>
<body>
<ext:ResourceManager runat="server" />
<ext:TreePanel
ID="TreePanel1"
runat="server"
Height="50"
RootVisible="false">
<Fields>
<ext:ModelField Name="url" />
</Fields>
<Root>
<ext:Node Expanded="true">
<Children>
<ext:Node Text="Ext.NET" Leaf="true" Href="sgdfs">
<CustomAttributes>
<ext:ConfigItem Name="url" Value="http://ext.net" Mode="Value" />
</CustomAttributes>
</ext:Node>
<ext:Node Text="Ext.NET forums" Leaf="true">
<CustomAttributes>
<ext:ConfigItem Name="url" Value="http://forums.ext.net" Mode="Value" />
</CustomAttributes>
</ext:Node>
</Children>
</ext:Node>
</Root>
</ext:TreePanel>
<ext:TabPanel ID="TabPanel1" runat="server" />
</body>
</html>

Antonio09
Jul 20, 2012, 11:28 PM

Daniil
Jul 21, 2012, 9:19 PM
I guess you have missed that section:

<Fields>
<ext:ModelField Name="url" />
</Fields>
of the TreePanel in my example.

Antonio09
Jul 23, 2012, 2:29 PM
Yes i did, it's working perfectly now.

Thank you Daniil.