I have a WebDataTree with two templates. I bind the data on the initial page load.
This works fine. My templates contain image buttons. If I click an image button, the data-derived portions of the template disappear. Loading the data during each postback causes other problems.
Is there anyway for this data to persist between postbacks?
Here is my html code:
<asp:Label runat="server" ID="lblCommandName" />
<asp:Label runat="server" ID="lblCommandArgument" />
<ig:WebDataTree ID="wdtCurricula" runat="server" DataMember="CATEGORIES" DataLoadingMessage="Please Wait"
DragDropSettings-AllowDrop="true" DragDropSettings-DragDropMode="Move" OnNodeBound="wdtCurricula_NodeBound"
OnItemCommand="wdtCurricula_ItemCommand">
<DragDropSettings AllowDrop="True" DragDropMode="Move">
</DragDropSettings>
<DataBindings>
<ig:DataTreeNodeBinding DataMember="CATEGORIES" TextField="Category" />
<ig:DataTreeNodeBinding DataMember="REPORTS_LIST" TextField="Display_Name" />
</DataBindings>
<Templates>
<ig:ItemTemplate ID="Template1" runat="server" TemplateID="Template1">
<Template>
<asp:ImageButton ID="ibAddLevel0" runat="server" AlternateText="Add" ToolTip="Add"
CausesValidation="false" CommandArgument="argLevel0" CommandName="AddLevel0"
ImageUrl="~/Images/icons/add_16.png" />
<asp:ImageButton ID="ibEdit" runat="server" AlternateText="Edit Student Score" ToolTip="Edit Student Score"
CausesValidation="false" CommandArgument="something" CommandName="Edit" ImageUrl="~/Images/icons/edit_enabled16x16.png" />
<asp:ImageButton ID="ibRemove" runat="server" AlternateText="Remove Student" ToolTip="Remove student from class."
CausesValidation="false" CommandArgument="something" CommandName="RemoveStudent"
ImageUrl="~/Images/icons/delete_enabled16x16.png" />
<asp:Label runat="server" ID="lblCategory" Text='<%# DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).DataItem, "Category")%>' />
</Template>
</ig:ItemTemplate>
<ig:ItemTemplate ID="Template2" runat="server" TemplateID="Template2">
<asp:ImageButton ID="ibAddLevel1" runat="server" AlternateText="Add" ToolTip="Add"
CausesValidation="false" CommandArgument="argLevel1" CommandName="AddLevel1"
ImageUrl="~/Images/icons/delete_enabled16x16.png" /><%# DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).DataItem, "Display_Name") %>
</Templates>
</ig:WebDataTree>
Here is the relevant C# code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
BindTree();
BindGrid();
}
private void BindTree()
wdtCurricula.DataSource = GetReportsDS();
wdtCurricula.DataBind();
protected void wdtCurricula_NodeBound(object sender, DataTreeNodeEventArgs e)
DataTreeNode thisNode = e.Node;
if (thisNode.Level == 0)
thisNode.TemplateId = Template1.TemplateID;
else
thisNode.TemplateId = Template2.TemplateID;
protected void wdtCurricula_ItemCommand(object sender, DataTreeCommandEventArgs e)
lblCommandName.Text = e.CommandName;
lblCommandArgument.Text = e.CommandArgument.ToString();
Thanks!
Hi jmakuch,
Thank you for posting in our forum.
I would suggest that you try to bind the WebDataTree on each page load and set EnableViewState to "false".
Please let me know if this helps.
Thanks for getting back to me!
Just to be sure I got it right, when you say to setEnableViewState="false", do you mean for the datatree control, or the entire page? I need to maintain a page viewstate on this page, so the latter is not an option for me.
Also, if I rebind the WebDataTree on each postback, it appears that the ItemCommand event for the WebDataTree is not triggered when I click my linkbutttons in the tree which are in my template.
Is there a way to maintain the data and also be able to capture clicking of the linkbuttons in the WebDataTree on postback?
Hi there,
In order to have this scenario of calling DataBinder.Eval() in your template working through postback, you need to rebind the WebDataTree every time the page is reloaded. If you're setting a data source programmatically, then set it on each load. You need to call DataBind() explicitly only the first time:
protected void Page_Load(object sender, EventArgs e){ WebDataTree1.DataSource = populateDataSet(); if (!IsPostBack) WebDataTree1.DataBind();}
Also you need to set EnableViewState="false" for the WebDataTree in order to not get validation errors for the parameters sent to the server as a result of the templates.
Let me know if you need additional assistance!
I will try this. Thanks!
Thank you for getting back to.
This might not work for me because I also need to know which node was clicked (DataTreeCommandEventArgs.Node). I don't think I can obtain this information in the OnCammand event of the button, can I?
Thanks again,
JMakuch
Hi,
I just got response from the development team with a possible workaround - instead of ItemCommand, use OnCommand event of the templated buttons and set EnableViewState to true. The dev team will continue to work on this issue.
I will inform you when I have more information regarding this.
As Konstantin stated above, the correct approach to bind the tree is to set the data source on each page load and call DataBind method only the first time. However, it seems that in this case the ItemCommand event is not firing. I’ve created a new development issue with ID 109942 to address this behavior.
If you have any questions, please let me know.