I'm running NetAdvantage 8.1 (one of the hotfixes) and have come across something I can't figure out.
I have a UltraWebTree with several nodes in it and I need to change the selected node client-side without actually posting back to the server-side NodeSelectionChanged event.
I found that, using the AfterNodeSelectionChanged client-side event I could look at a flag (I created) and abort the selectionchanged.
This originally appears to work until the very next postback to the server, which then mysteriously fires the NodeSelectionChanged event. It's like some state is still in the treeview telling it to fire this event.
I created an extremely simple web page that shows this problem. The form has a tree, two buttons and a textbox. If you click the first button, which is setup to be a clientside only button, fires code that manually calles setSelected(true) on the client. There is no postback to the server as expected (because it hits my client code to abort selectionchanged). But if I click the 2nd button, both the button click event and the NodeSelectionChanged events fire. NodeSelectionChanged event shouldn't fire.
Here is the source...
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TreeViewCSOMEventProblem._Default" %><%@ Register assembly="Infragistics35.WebUI.UltraWebNavigator.v8.1, Version=8.1.20081.2058, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" namespace="Infragistics.WebUI.UltraWebNavigator" tagprefix="ignav" %><!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></title> <script type="text/javascript" id="igClientScript"><!-- var WebTree; var bAbortSelectionChanged = false; function myClientClick() { // manually select second node var nodes = WebTree.getNodes(); bAbortSelectionChanged = true; nodes[1].setSelected(true); return (false); } function UltraWebTree1_BeforeNodeSelectionChange(treeId, oldNodeId, newNodeId) { // can't do it here because node isn't selected then //if (bAbortSelectionChanged == true) { // return true; //} } function UltraWebTree1_AfterNodeSelectionChange(treeId, nodeId) { if (bAbortSelectionChanged == true) { WebTree.CancelPostBack = true; WebTree.NeedPostBack = false; event.cancelBubble = true; bAbortSelectionChanged = false; return true; } } function UltraWebTree1_InitializeTree(treeId) { WebTree = igtree_getTreeById(treeId); }// -->// --> </script></head><body> <form id="form1" runat="server"> <div> <ignav:UltraWebTree ID="UltraWebTree1" runat="server" DefaultImage="" HiliteClass="" HoverClass="" Indentation="20" onnodeselectionchanged="UltraWebTree1_NodeSelectionChanged" Width="250px"> <ClientSideEvents AfterNodeSelectionChange="UltraWebTree1_AfterNodeSelectionChange" InitializeTree="UltraWebTree1_InitializeTree" BeforeNodeSelectionChange="UltraWebTree1_BeforeNodeSelectionChange" /> <Levels> <ignav:Level Index="0" /> <ignav:Level Index="1" /> </Levels> <Nodes> <ignav:Node TagString="Inbox" Text="Inbox"> <Nodes> <ignav:Node TagString="IC1" Text="Inbox Child"> </ignav:Node> </Nodes> </ignav:Node> <ignav:Node TagString="Received" Text="Received"> <Nodes> <ignav:Node TagString="RC1" Text="Received Child"> </ignav:Node> </Nodes> </ignav:Node> </Nodes> </ignav:UltraWebTree> </div> <asp:Button ID="Button1" runat="server" OnClientClick="return myClientClick();" Text="CSOM Select" /><br /> <asp:Button ID="Button2" runat="server" Text="PostBack" onclick="Button2_Click" /><br /> <asp:TextBox ID="TextBox1" runat="server" Width="400px"></asp:TextBox> </form></body></html>
here is the code-behind
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;namespace TreeViewCSOMEventProblem{ public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { // have first node selected and expand all by default UltraWebTree1.Nodes[0].Selected = true; UltraWebTree1.ExpandAll(); TextBox1.Text = ""; } } protected void UltraWebTree1_NodeSelectionChanged(object sender, Infragistics.WebUI.UltraWebNavigator.WebTreeNodeEventArgs e) { TextBox1.Text += "Selection Changed Fired!"; } protected void Button2_Click(object sender, EventArgs e) { TextBox1.Text += "Server-Side Button Clicked!"; } }}
Any help would be greatly appreciated!
Hello nuhfeken,
It has been a while since you have made your post but I suppose the other community members can benefit from this answer as well.
This behavior is most probably caused by the selection changed made on the tree from Client-Side. When Postback is made the tree probably gets the selected node and since it is not the same as the one initially selected the “NodeSelectionChanged” event is fired.
I hope that this information is helpful.