Home - Forums-.NET - FlyTreeView (ASP.NET) - Have issue - very simple test not working...

FlyTreeView (ASP.NET)

Technical support and KB related to the FlyTreeView control

This forum related to following products: FlyTreeView for ASP.NET

Have issue - very simple test not working...
Link Posted: 16-Apr-2007 20:08
I am demoing the FlyTreeView control and like the control itself. My problem comes when I try to change anything (non tree view) else on my page, based on an event in the FlyTreeView. All I am trying to do is increment a label on the page by 1 for every time the PopulateNodes event is called. The label updates the first time the page is loaded (and the first set of nodes is populated), but after that the label is never updated again - EVEN though all levels of the nodes can be populated. Am I missing something?

My code (client side):








In my code behind:

protected void TreeView1_PopulateNodes(object sender, FlyTreeNodeEventArgs e)
    {
        try
        {
            NameValueCollection listNodes = null;
            IL.LevelType level = IL.LevelType.None;
            IL.SearchCriteria critiera = new IL.SearchCriteria();

            switch (e.Node.Level)
            {
                case 0:             //root node. Level: Region
                    listNodes = ConvertNameValue(CachedLists.RegionList);
                    level = IL.LevelType.Region;
                    critiera.RegionID = int.Parse(e.Node.Value);
                    break;
                case 1:             //district/credited district
                    level = IL.LevelType.Region;
                    
                    if (SearchFilters1.CreditedDistrictMode)
                    {
                        listNodes = ConvertNameValue(CachedLists.RegionCreditedDistrictList(int.Parse(e.Node.Value)).DistinctList);
                        critiera.CreditedDistrictID = int.Parse(e.Node.Value);
                    }
                    else
                    {
                        listNodes = ConvertNameValue(CachedLists.RegionDistrictList(int.Parse(e.Node.Value)).DistinctList);
                        critiera.DistrictID = int.Parse(e.Node.Value);
                    }
                    break;
                case 2:             //atu manager
                    level = (SearchFilters1.CreditedDistrictMode) ? IL.LevelType.CreditedDistrict : IL.LevelType.District;
                    IL.GeoFilters filters = new IL.GeoFilters();

                    if (SearchFilters1.CreditedDistrictMode)
                        filters.CreditedDistrictID = int.Parse(e.Node.Value);
                    else
                        filters.DistrictID = int.Parse(e.Node.Value);

                    critiera.ATUManagerAlias = e.Node.Value;
                    listNodes = ConvertNameValue(CachedLists.ATUManagerList.FilteredList(filters));
                    break;
                case 3:             //account manager
                    level = IL.LevelType.ATUManager;
                    critiera.AccountManagerAlias = e.Node.Value;
                    listNodes = ConvertNameValue(CachedLists.AccountManagerList.FilteredList(e.Node.Value, new IL.GeoFilters()));
                    break;
                case 4:             //account
                    level = IL.LevelType.AccountManager;
                    //critiera.
                    listNodes = ConvertNameValue(CachedLists.AccountList.FilteredList(string.Empty, e.Node.Value, new IL.GeoFilters()));
                    break;
            }

            if (listNodes != null)
            {
                //set up child nodes to populate
                for (int i = 0; i < listNodes.Count; i++)
                {
                    FlyTreeNode childNode = new FlyTreeNode(listNodes.GetValues(i)[0], listNodes.Keys[i]);
                    childNode.PopulateNodesOnDemand = (level != IL.LevelType.Account);
                    childNode.NavigateUrl = SearchFilters1.NavigateURL(\"Summary.aspx\", level, listNodes.Keys[i]);
                    childNode.Expanded = false;
                    e.Node.ChildNodes.Add(childNode);
                }
            }


int counter = 0;
if (Session[\"counter\"] != null)
      counter = (int)Session[\"counter\"];

counter++;

lblTest.Text = \"We've been called \" + counter + \" times!\";

Session[\"counter\"] = counter;

//BELOW IS WHAT EVENTUALLY SHOULD BE HAPPENING - POPULATING A SERIES OF REPEATERS (REPRESENTING HORIZONTAL ROWS OF DATA) ADJACENT TO NODES IN THE TREEVIEW. FOR NOW, I'LL JUST SETTLE FOR THE LABEL UPDATING. :P

            //get current rowList if in ViewState
            if (ViewState[\"RowList\"] != null)
                _rowList = ViewState[\"RowList\"] as ILC.RowList;

            //run manual search of newly expanded level. for now, these rows are appended.
            _rowList.AddRowList(ILC.RowList.GetRowList(critiera));

            //persist rows back to viewstate
            ViewState[\"RowList\"] = _rowList;

            rptSockets.DataSource = _rowList.SocketList;
            rptSockets.DataBind();
        }
        catch (Exception ex)
        {
            ShowError(\"expanding Node\", ex, true);
        }
    }


One more thing - I am eventually going to be using this in an UpdatePanel, but I've tried several combinations of this without success..  

Thanx for your thoughts!
Link Posted: 16-Apr-2007 20:41
Ok, I wrapped the label and FlyTreeView in an UpdatePanel and then set OnExpandPostBack = true on the TreeView and the label seems to be updating properly. I assume that the FlyTreeView is initiating a post back, which is then being received and paritally rendered by the containing UpdatePanel, correct?

One problem with using that setting though - since I also use OnPopulateNodes and PopulateNodesOnDemand (on each node) - the PopulateNodes event is firing twice! That won't do.. any advice?

Thanks again..
Link Posted: 17-Apr-2007 00:28
[quote="JCannelos"]All I am trying to do is increment a label on the page by 1 for every time the PopulateNodes event is called. The label updates the first time the page is loaded (and the first set of nodes is populated), but after that the label is never updated again - EVEN though all levels of the nodes can be populated. Am I missing something?

This is a normal behavior since FlyTreeView loads its nodes without page refresh. It means that no postback occurs when you expand some node, but rather callback is initiated instead. So that the treeview updates its nodes using the data transfered back from the server.

Of course if you need the whole page to be updated when you expand some node then you need to set FlyTreeView.PostbackOnExpand (or FlyNodeType.PostbackOnExpand if you're using several node types).
Link Posted: 17-Apr-2007 00:40
[quote="JCannelos"]
One problem with using that setting though - since I also use OnPopulateNodes and PopulateNodesOnDemand (on each node) - the PopulateNodes event is firing twice! That won't do.. any advice?

This is a side effect of using PopulateNodesOnDemand and PostbackOnExpand simultaneously. The first time occurs when treeview starts loading  nodes using callback the second one when nodes are actually added to treeview structure (at postback). So only the second call actually adds nodes to treeview.

In your case you can simply ignore first call by using IsCallback page property.
if (!IsCallback) {
  // your actions to add nodes to treeview.
}
Link Posted: 17-Apr-2007 04:47
Awesome, I got it working..

Thanx for your quick resonse, EvgenyT!