[CLOSED] Reloading a TreePanel with new Parameters

  1. #1

    [CLOSED] Reloading a TreePanel with new Parameters

    I have a simple TreePanel using a TreeStore that is using a Proxy to a simple WebService. The WebService requires a parameter. On the initial load, the TreePanel populates correctly.
    My problem is when adding a Button that is using it's OnClientClick to change the parameter for the TreeStore. How can I make the TreePanel re-render itself with the new values from the webservice?

    Here is my code:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ExtNetTreePanel.aspx.cs" Inherits="adpass.client.extnet.ExtNetTreePanel" %>
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>ExtNetTreePanel Example</title>
        <script>
            function getJsonResponseData(response) {
                try {
                    return this.readRecords(Ext.decode(Ext.decode(response.responseText).d));
                } catch (ex) {
                    var error = new Ext.data.ResultSet({
                        total: 0,
                        count: 0,
                        records: [],
                        success: false,
                        message: ex.message
                    });
    
                    this.fireEvent('exception', this, response, error);
    
                    return error;
                }
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <ext:ResourceManager runat="server" />
            
            <h1>TreePanel using WebService</h1> 
    
            <ext:Container runat="server"
                Layout="HBoxLayout">
                <Items>
                    <ext:TreePanel 
                        ID="treePanel" 
                        runat="server" 
                        Title="JSON WebService" 
                        Height="500"
                        Width="200" 
                        Margins="10"
                        Border="false">
                        <Store>
                            <ext:TreeStore runat="server">
                                <Proxy>
                                    <ext:AjaxProxy Url="TreeJsonService.asmx/GetNodes" Json="true">
                                        <ActionMethods Read="POST" />
                                        <Reader>
                                            <ext:JsonReader>
                                                <CustomConfig>
                                                    <ext:ConfigItem Name="getResponseData" Value="getJsonResponseData" Mode="Raw" />
                                                </CustomConfig>
                                            </ext:JsonReader>
                                        </Reader>
                                    </ext:AjaxProxy>
                                </Proxy>
                                <Parameters>
                                    <ext:StoreParameter Name="strParam" Value="start" />                                    
                                </Parameters>
                            </ext:TreeStore>
                        </Store>
                        <Root>
                            <ext:Node NodeID="0" Text="Root" />
                        </Root>
                    </ext:TreePanel>
                    <ext:Button ID="btnLoad" Text="Reload" OnClientClick="#{treePanel}.store.load({params:{strParam:'end'}});">
                    </ext:Button>
                </Items>
            </ext:Container>
         </form>
    </body>
    </html>
    And the code for the WebService:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Services;
    
    namespace adpass.client.extnet
    {
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        [System.Web.Script.Services.ScriptService]
        public class TreeJsonService : System.Web.Services.WebService
        {
    
            [WebMethod]
            public string GetNodes(string strParam)
            {
                Ext.Net.NodeCollection nodes = new Ext.Net.NodeCollection(false);
    
                if (!string.IsNullOrEmpty(strParam))
                {
                    for (int i = 1; i < 6; i++)
                    {
                        Ext.Net.Node asyncNode = new Ext.Net.Node();
                        asyncNode.Text = strParam + "-" + i;
                        asyncNode.NodeID = strParam + i;
                        nodes.Add(asyncNode);
                    }
    
                    for (int i = 6; i < 11; i++)
                    {
                        Ext.Net.Node treeNode = new Ext.Net.Node();
                        treeNode.Text = strParam + "-" + i;
                        treeNode.NodeID = strParam + i;
                        treeNode.Leaf = true;
                        nodes.Add(treeNode);
                    }
                }
    
                return nodes.ToJson();
            }
        }
    }
    Last edited by Daniil; Mar 21, 2014 at 12:24 PM. Reason: [CLOSED]
  2. #2
    Hi @chulcy,

    Welcome to the Ext.NET forums!

    Please use:
    <ext:StoreParameter Name="strParam" Value="start" ApplyMode="IfNotExists" />
  3. #3
    Thank you very much Daniil
    That worked!

    Can you explain why that works, please?
    Thanks!
  4. #4
    Defaults to:
    ApplyMode="Always"
    It means a priority. It overrides a parameter you pass to a TreeStore's load call.

Similar Threads

  1. [CLOSED] Reloading TreePanel Nodes dynamically in a Direct Event
    By rmelancon in forum 2.x Legacy Premium Help
    Replies: 2
    Last Post: Mar 17, 2014, 11:31 AM
  2. Replies: 4
    Last Post: May 24, 2012, 3:08 PM
  3. About reloading a TreePanel...
    By kabalkunz in forum 1.x Help
    Replies: 0
    Last Post: Oct 28, 2011, 3:59 PM
  4. Replies: 2
    Last Post: Dec 08, 2009, 4:54 PM
  5. Add Parameters to TreePanel treenodes
    By andrlar in forum 1.x Help
    Replies: 2
    Last Post: May 15, 2009, 4:01 AM

Posting Permissions