Showing posts with label populateondemand. Show all posts
Showing posts with label populateondemand. Show all posts

Monday, March 26, 2012

TreeView PopulateOnDemand within AccordionPane

I have an accordion inside of an Accordion Panel, which is generated from a database. I have the treeview set to populate on demand if there are any subnodes, using the TreeNodePopulate event of the TreeView. Since the Tree is inside of the Accordion Pane, I lose design support, and have to explicitly find and cast the control from the Accordion object. Becuase of this, I lose the event handling binding to that Treeview node. I'm not sure If explicitly fetching and casting is right to begin with, so I'd rather not waste a lot of time trying to manually wire the events to the casted TreeView in codebehind if there is a better way.

Expand Category 1

The target 'ctl00$ContentPlaceHolder2$ctl01$TreeView1' for the callback could not be found or did not implement ICallbackEventHandler.

<atlastoolkit:AccordionPane ID="AccordionPane2" runat="server">
<Header>
<a href="http://links.10026.com/?link=" onclick="return false;" class="accordionLink">Panel 2</a></Header>
<Content>
<asp:TreeView ID="TreeView1" ExpandDepth="0" PopulateNodesFromClient="true" ShowLines="true"
ShowExpandCollapse="true" runat="server" OnTreeNodePopulate="TreeView1_TreeNodePopulate" />
</Content>
</atlastoolkit:AccordionPane>

TreeView tree1;

protected void Page_Load(object sender, EventArgs e)
{
tree1 = (TreeView)AccordionPane2.ContentContainer.FindControl("TreeView1");

}

protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
PopulateSubLevel(Convert.ToInt32(e.Node.Value), e.Node);
}

private void PopulateSubLevel(int parentid, TreeNode parentNode)
{
SqlConnection objConn = new SqlConnection(@dotnet.itags.org."server=SYSSIMERT01\SQLEXPRESS;Trusted_Connection=true;DATABASE=TreeViewSampleDB");
SqlCommand objCommand = new SqlCommand("select id,title,(select count(*) FROM SampleCategories WHERE parentid=sc.id) childnodecount FROM SampleCategories sc where parentID=@dotnet.itags.org.parentID", objConn);

objCommand.Parameters.Add("@dotnet.itags.org.parentID", SqlDbType.Int).Value = parentid;

SqlDataAdapter da = new SqlDataAdapter(objCommand);
DataTable dt = new DataTable();
da.Fill(dt);
PopulateNodes(dt, parentNode.ChildNodes);
}

Hi j05h,

It sounds like the event isn't being properly wired up whenever you postback. If you're creating controls dynamically (and then also their event handlers), be sure to recreate them on postback. If this doesn't help, perhaps you can provide asmall sample demonstrating the problem that I can run.

Thanks,
Ted

treeview updatepanel problem

hi,

i have a treeview inside an updatepanel. I'm using ajax ext beta 1

the treeview make use of the node expand with PopulateOnDemand = True

when i select a leaf node the treeeview is regenerated with one or more node that i have not added and than stop working.

I think this is a problem of the treeview with updatepanel because if I remove the updatepanel the treeview work fine.

can anyone help me to solve the problem?

thanks

this is the source code...

Protected Sub Page_Load(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles Me.LoadIf Not Page.IsPostBackThen trv1.Nodes.Clear() trv1.Nodes.Add(New XTreeNode("Root node","A")) trv1.Nodes(0).ChildNodes.Add(New XTreeNode("trv1_node 1","1.1")) trv1.Nodes(0).ChildNodes.Add(New XTreeNode("trv1_node 2","1.2"))'trv1.Nodes(0).ChildNodes(0).Select() trv1.Nodes(0).ChildNodes(0).PopulateOnDemand =True trv1.Nodes(0).ChildNodes(0).SelectAction = TreeNodeSelectAction.Expand trv1.ExpandDepth = 1End If End Sub Protected Sub trv1_TreeNodePopulate(ByVal senderAs Object,ByVal eAs System.Web.UI.WebControls.TreeNodeEventArgs)Handles trv1.TreeNodePopulateDim pNodeAs TreeNode = e.NodeDim pNewNodeAs TreeNode =New TreeNode("New Node","NN") pNewNode.PopulateOnDemand =True pNewNode.SelectAction = TreeNodeSelectAction.Expand pNode.ChildNodes.Add(pNewNode)End Sub

i've tried also the beta 2 but the problem remains the same!!

can anyone help me to solve the problem?


I heard it isn't supported with the Betas or RC, but I heard it may be eventually... I did work before the Betas though.

TreeView, UpdatePanel PopulateOnDemand problem

When I use a PopulateOnDemand TreeView inside an UpdatePanel - when I click on the root node to populate its immediate children, it expands with the child nodes displayed. If I then click on any of the child nodes, the root node collapses. This does not happen if not in an UpdatePanel.

Also, if I click on the root node again and then click on an immediate child to populate its children, it has the same behavior. After the root node automatically collapses, if I click on the root node again, all child nodes that were expanded will still be expanded.

Does anyone know how I can get the root node to not automatically collapse when I click on any of its descendent nodes?

The TreeView isn't supported inside an UpdatePanel, see the last bullet point on this blog and follow the UpdatePanel doc link:http://blogs.visoftinc.com/archive/2007/09/23/asp.net-ajax--updatepanel-not-working--common-problems.aspx

PopulateOnDemand PopulateNodesFromClient actually uses client script as it is.

-Damien


Thanks for the response. When you say that it uses client script, what does that mean? PopulateOnDemand seems to cause full page refreshes - even when I use EnableClientScript and PopulateNodesFromClient...


That's what PopulateNodesFromClient does:http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.treeview.populatenodesfromclient.aspx.

The example states:"The following code example demonstrates how to use thePopulateNodesFromClient property to enable client-side population of the nodes in theTreeView control. Notice that when client-side node population is enabled, nodes are populated dynamically on the client, without the need to post back to the server."

-Damien


Thanks. My point was that it still caused a full page refresh. If it was happening on the client (using Ajax), then I wouldn't see a full page refresh. It turns out that I had to take out my TreeNodeExpanded and TreeNodeCollapsed event handlers to get rid of the full page refresh. After doing that, though, child nodes (that definitely have a parent node) have their Parent property set to null.

I am making headway though...thanks for your help.


You may want to check out this:http://steveorr.net/articles/Ajax.aspx

-Damien


Thanks. Good article. But it still does not explain why the Parent property is null on a child node. Again, this only happens with EnableClientScript, PopulateNodesFromClient and without TreeNodeExpanded and TreeNodeCollapsed event handlers. I need the Parent node for context so I can populate nodes more than 2 deep.