Sep 21, 2011, 3:14 PM
How can i use a dynamic user control more than once in a aspx page?
Steps to reproduce:
I have an user control "MyGenericTreePanel.ascx" consisting following:
1. A TreePanel with Async TreeNode
2. Displays data from a ajax call
MyGenericTreePanel.ascx
I really want to make use of generic user control for all of these steps. Can anyone please suggest that how can i load different data sources for different steps? Is my approach seems simple or i am unnecessary making it complex.
Any suggestion would be helpful.
Thanks
I have an user control "MyGenericTreePanel.ascx" consisting following:
1. A TreePanel with Async TreeNode
2. Displays data from a ajax call
MyGenericTreePanel.ascx
<%@ Control Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<script type="text/javascript" language="javascript">
function LoadGenericTreePanel(selectedNode) {
var model= { NodeId: selectedNode.id, Nodes: "" }
//Making an ajax call and on callback binding data to current asyncTree node // I am mocking data for your test puspose.
model.Nodes = [{id:"1",iconCls:"icon-folder",text:"Node1-Text",nodeType:"async"},{id:"2",iconCls:"icon-folder",text:"Node2-Text",nodeType:"async"}]
var data = eval("(" + model.Nodes+ ")");
selectedNode.loadNodes(data);
}
</script>
<ext:TreePanel ID="GenericTreePanel" runat="server" Height="500" Width="400" UseArrows="true"
AutoScroll="true" Animate="false" EnableDD="true" ContainerScroll="true">
<Root>
<ext:AsyncTreeNode NodeID="0" Expanded="true" Icon="Group" SingleClickExpand="true" />
</Root>
<Listeners>
<BeforeLoad Fn="LoadGenericTreePanel" />
</Listeners>
</ext:TreePanel>
Now i have a aspx page where i need to display multiple instance of this user control for different steps, i.e. i need to use this same tree panel user control for different scenarios at same time. Here is my aspx page: At one time only step would be visible to user and rest would be hidden.<%@ Page Language="C#" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Register Src="~/MyGenericTreePanel.ascx" TagPrefix="extUC" TagName="GenericTreePanel" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Test Page</title>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<div class="wizard-step-1">
<h3>
Step 1: </h3>
<extUC:GenericTreePanel ID="userControl1" runat="server" />
</div>
<div class="wizard-step-2">
<h3>
Step 2: </h3>
<extUC:GenericTreePanel ID="userControl2" runat="server" />
</div>
<div class="wizard-step-3">
<h3>
Step 3: </h3>
<extUC:GenericTreePanel ID="userControl3" runat="server" />
</div>
</form>
</body>
</html>
Problem:
At the moment if i run this page then tree panel in div="wizard-step-3" is loading Nodes data 3 times though rest of tree panels from "wizard-step-1" & "wizard-step-2" remains empty.
Any suggestion would be helpful.
Thanks