[CLOSED] Trying to access a control with 'X.GetCmp<TreePanel>("TreePanel1")' when I added it dynamically

  1. #1

    [CLOSED] Trying to access a control with 'X.GetCmp<TreePanel>("TreePanel1")' when I added it dynamically

    I added a TreePanel form the code behind like the snippet below:

    .cs
     protected void Page_Load(object sender, EventArgs e)
    {
                var tree = new TreePanel();
                PlaceHolder1.Controls.Add(tree);
                tree.ID = "TreePanel1";
                ...
    }
    .aspx
           <asp:PlaceHolder ID="PlaceHolder1" runat="server" />

    I CAN'T access 'TreePanel1' with the code below, is 'null'
    var tree = X.GetCmp<TreePanel>("TreePanel1").GetSelectionModel();
    Last edited by Daniil; Jul 31, 2012 at 12:43 PM. Reason: [CLOSED]
  2. #2
    Hi,

    I have discovered that the following example causes a JavaScript error.
    TypeError: this.node is null
    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            var tree = new TreePanel();
            tree.Root.Add(new Node());
            tree.ID = "TreePanel1";
            this.Controls.Add(tree);
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
    </body>
    </html>
    Could you confirm?

    Anyways, we are investigating the issue.

    Regarding this:
    var tree = X.GetCmp<TreePanel>("TreePanel1").GetSelectionModel();
    It won't work, because X.GetCmp just returns a TreePanel proxy. It knows nothing about its selection model.

    In your case since you recreate a control every request, you can just find the real TreePanel control.

    Example
    protected void GetCount(object sender, DirectEventArgs e)
    {
        TreePanel tree = Ext.Net.Utilities.ControlUtils.FindControl<TreePanel>(this, "TreePanel1");
        TreeSelectionModel sm = (tree.GetSelectionModel() as TreeSelectionModel);
        int count = 0;
    
        if (sm.SelectedNodes != null)
        {
            count = sm.SelectedNodes.Count;
        }
    
        X.Msg.Alert("Selected nodes", count).Show();
    }
  3. #3
    Yip, it DOES cause an error
    "Microsoft JScript runtime error: 'this.node' is null or not an object"

    Thanks, that works for me.

    Quote Originally Posted by Daniil View Post
    Hi,

    I have discovered that the following example causes a JavaScript error.
    TypeError: this.node is null
    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            var tree = new TreePanel();
            tree.Root.Add(new Node());
            tree.ID = "TreePanel1";
            this.Controls.Add(tree);
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
    </body>
    </html>
    Could you confirm?

    Anyways, we are investigating the issue.

    Regarding this:
    var tree = X.GetCmp<TreePanel>("TreePanel1").GetSelectionModel();
    It won't work, because X.GetCmp just returns a TreePanel proxy. It knows nothing about its selection model.

    In your case since you recreate a control every request, you can just find the real TreePanel control.

    Example
    protected void GetCount(object sender, DirectEventArgs e)
    {
        TreePanel tree = Ext.Net.Utilities.ControlUtils.FindControl<TreePanel>(this, "TreePanel1");
        TreeSelectionModel sm = (tree.GetSelectionModel() as TreeSelectionModel);
        int count = 0;
    
        if (sm.SelectedNodes != null)
        {
            count = sm.SelectedNodes.Count;
        }
    
        X.Msg.Alert("Selected nodes", count).Show();
    }
  4. #4
    Quote Originally Posted by Fahd View Post
    Yip, it DOES cause an error
    "Microsoft JScript runtime error: 'this.node' is null or not an object"
    Thanks for confirmation! We are investigating.
  5. #5
    Quote Originally Posted by Daniil View Post
    I have discovered that the following example causes a JavaScript error.
    TypeError: this.node is null
    Example
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
            var tree = new TreePanel();
            tree.Root.Add(new Node());
            tree.ID = "TreePanel1";
            this.Controls.Add(tree);
        }
    </script>
    
    <!DOCTYPE html>
    
    <html>
    <head runat="server">
        <title>Ext.NET v2 Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server" />
    </body>
    </html>
    it has been fixed in SVN.
  6. #6
    Thank you...

    Quote Originally Posted by Daniil View Post
    it has been fixed in SVN.

Similar Threads

  1. [CLOSED] How does "MaskCls" work for "AutoLoad" mask in panel control
    By leon_tang in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Jul 19, 2012, 12:09 PM
  2. Replies: 2
    Last Post: May 03, 2012, 3:12 PM
  3. Replies: 5
    Last Post: May 02, 2012, 5:37 PM
  4. Replies: 6
    Last Post: Nov 04, 2010, 10:14 AM
  5. Replies: 1
    Last Post: Nov 03, 2010, 7:31 PM

Tags for this Thread

Posting Permissions