Saturday, March 24, 2012

Atlas TreeView PopulateOndemand issue

I am trying to implement atlas in a treeView which is populated from an XML. When the tree child nodes are populatedOndemand how we can implement Atlas in it ?
I tried to incorporate UpdatePanel programatically but didnt succeed. This is my demo code :

<%@dotnet.itags.org. Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<atlas:ScriptManager EnablePartialRendering=True ID="ScriptManager1" runat="server" />
<atlas:UpdatePanel ID="UpdateP" runat=server>
<ContentTemplate>
<div> <asp:TextBox ID="TextBox1" runat="server" OnTextChanged="TextBox1_TextChanged"></asp:TextBox> </div>
</ContentTemplate>
<Triggers >
<atlas:ControlEventTrigger ControlID="Button1" EventName="Click" />
<atlas:ControlEventTrigger ControlID="TreeView1" EventName="TreeNodeExpanded" />
</Triggers>
</atlas:UpdatePanel>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<div>
<asp:TreeView ID="TreeView1" Runat="server" ExpandImageUrl="Images/closed.gif" CollapseImageUrl="Images/open.gif" DataSourceID="XmlDataSource1" ExpandDepth="0">
<DataBindings>
<asp:TreeNodeBinding DataMember="categories" TextField="#Name" PopulateOnDemand="True" SelectAction="Expand"/>
<asp:TreeNodeBinding DataMember="category" ValueField="id" TextField="name" PopulateOnDemand="True" SelectAction="Expand"/>
<asp:TreeNodeBinding DataMember="desc" ValueField="value" TextField="value" PopulateOnDemand="True"/>
</DataBindings>
</asp:TreeView>
<asp:XmlDataSource ID="XmlDataSource1" Runat="server" DataFile="~/App_Code/Categories.xml"
TransformFile="~/App_Code/Categories.xsl" />
</div>
</form>

</body>
</html
-------
<?xml version='1.0'?>
<!-- This file represents a fragment of a Categories inventory database -->
<Categories>
<Category ID="1" Name="Beverages">
<Description Value="Soft drinks, coffees, teas, beers, and ales"/>
</Category>
<Category ID="2" Name="Condiments">
<Description Value="Sweet and savory sauces, relishes, spreads, and seasonings"/>
</Category>
<Category ID="3" Name="Confections">
<Description Value="Desserts, candies, and sweet breads"/>
</Category>
<Category ID="4" Name="Dairy Products">
<Description Value="Cheeses"/>
</Category>
</Categories>
--------
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<categories>
<xsl:for-each select="//Categories/Category">
<category>
<xsl:attribute name="id">
<xsl:value-of select="@dotnet.itags.org.ID"/>
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="@dotnet.itags.org.Name"/>
</xsl:attribute>
<xsl:element name="desc">
<xsl:attribute name="value">
<xsl:value-of select="Description/@dotnet.itags.org.Value"/>
</xsl:attribute>
</xsl:element>
</category>
</xsl:for-each>
</categories>
</xsl:template>
</xsl:stylesheet
Hope someone in the group has already tried something like this.
Cheers

I had the similar issue. I guess the issue is due to how clend side event for "Populate on demand" works. Nodes are not actually added to the tree untill the next post back operation ( even though you preview it after user expands the tree). You can see this behaviour by going through debugging. The event "TreeNodePopulate" is called twice. Once when user expands the tree and the other after any next post back event to the page.

Since you put atlas update panel around the tree, full post back is probabally not happening for the tree view. The work around that I used was.

- Add "TreeNodePopulate" event as a trigger in your update panel

- Turn off the client behaviour of tree expand ( putPopulateNodesFromClient = false ) and let atlas take care of it.

It worked for me. let us know what happened in your case.

hgrewa.

No comments:

Post a Comment