Script Error

  1. #1

    Script Error



    Hi

    My English not good. I encountered an error. Please help me. Thanks
    
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        [AjaxMethod]
        public static string NodeLoad (string nodeID)
        {
    
            Coolite.Ext.Web.TreeNodeCollection nodes = new Coolite.Ext.Web.TreeNodeCollection();
            Coolite.Ext.Web.TreeNode temp1 = new Coolite.Ext.Web.TreeNode("myid","myname",Icon.Page);    
            temp1.Leaf = true;
            temp1.Listeners.Click.Handler = "addTab(#{TabPanel1}, 'id', 'http://www.google.com');";
            nodes.Add(temp1);
            return nodes.ToJson();
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <script type="text/javascript">
            function nodeLoad(node) {
                Coolite.AjaxMethods.NodeLoad(node.id, {
                    success: function(result) {
                        var data = eval("(" + result + ")");
                        node.loadNodes(data);
                    },
    
                    failure: function(errorMsg) {
                        Ext.Msg.alert('Failure', errorMsg);
                    }
                });
            };
    
            function addTab(tabPanel, id, url) {
                alert('1');
                var tab = tabPanel.getComponent(id);
                alert('2');
                if (!tab) {
                  var  tab = tabPanel.add({
                        id: id,
                        title: url,
                        closable: true,
                        autoLoad: {
                            showMask: true,
                            url: url,
                            mode: 'iframe',
                            maskMsg: 'Loading ' + url + '...'
                        }
                    });
                }
             tabPanel.setActiveTab(tab);
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <ext:ScriptManager ID="ScriptManager1" runat="server">
        </ext:ScriptManager>
        <ext:ViewPort ID="ViewPort1" runat="server" >
                <Body>
                    <ext:BorderLayout ID="BorderLayout1" runat="server">
                        <West Collapsible="true" Split="true" >
                             <ext:TreePanel 
                                 ID="TreePanel1" 
                                 runat="server" 
                                 Title="Tree" 
                                 AutoHeight="false" 
                                 Border="false"
                                 Width="200"
                                 >
                                 <Root>
                                     <ext:AsyncTreeNode NodeID="test" Text="Root"  />
                                 </Root>
                                 <Listeners>
                                   <BeforeLoad Fn="nodeLoad" />
                                 </Listeners>
                            </ext:TreePanel>  
                        </West>
                        <Center>
                            <ext:TabPanel ID="TabPanel1" runat="server">                               
                            </ext:TabPanel>
                        </Center>
                    </ext:BorderLayout>
                </Body>
            </ext:ViewPort>
        </form>
    </body>
    </html>
  2. #2

    RE: Script Error

    Hi,

    You can't use #{TabPanel1} in static context because the controls is not accessable in static context.

    I can suggest the following solutions:

    Solution 1. Remove static from AjaxMethod

    Solution 2. Hardcore tab panel id
    [AjaxMethod]
        public static string NodeLoad (string nodeID)
        {
            Coolite.Ext.Web.TreeNodeCollection nodes = new Coolite.Ext.Web.TreeNodeCollection();
            Coolite.Ext.Web.TreeNode temp1 = new Coolite.Ext.Web.TreeNode("myid","myname",Icon.Page);    
            temp1.Leaf = true;
            temp1.Listeners.Click.Handler = "addTab(TabPanel1, 'id', 'http://www.google.com');";
            nodes.Add(temp1);
            return nodes.ToJson();
        }
    Solution 3. Save TabPanel clientID in session (if session available in your project)
    protected void Page_Load(object sender, EventArgs e)
        {
            Session["TabPanel1"] = TabPanel1.ClientID;
        }
        
        [AjaxMethod]
        public static string NodeLoad (string nodeID)
        {
            Coolite.Ext.Web.TreeNodeCollection nodes = new Coolite.Ext.Web.TreeNodeCollection();
            Coolite.Ext.Web.TreeNode temp1 = new Coolite.Ext.Web.TreeNode("myid","myname",Icon.Page);    
            temp1.Leaf = true;
            temp1.Listeners.Click.Handler = "addTab("+ HttpContext.Current.Session["TabPanel1"] +", 'id', 'http://www.google.com');";
            nodes.Add(temp1);
            return nodes.ToJson();
        }
    Solution 4. Register js variable
     protected void Page_Load(object sender, EventArgs e)
        {
            this.ScriptManager1.Listeners.DocumentReady.Handler = string.Concat("this.myTabPanel1 = ", TabPanel1.ClientID, ";");
        }
        
        [AjaxMethod]
        public static string NodeLoad (string nodeID)
        {
            Coolite.Ext.Web.TreeNodeCollection nodes = new Coolite.Ext.Web.TreeNodeCollection();
            Coolite.Ext.Web.TreeNode temp1 = new Coolite.Ext.Web.TreeNode("myid","myname",Icon.Page);    
            temp1.Leaf = true;
            temp1.Listeners.Click.Handler = "addTab(myTabPanel1, 'id', 'http://www.google.com');";
            nodes.Add(temp1);
            return nodes.ToJson();
        }

    Vladimir Shcheglov
    Sr. Developer
  3. #3

    RE: Script Error

    Thanks!

Similar Threads

  1. Replies: 17
    Last Post: Oct 12, 2011, 4:54 PM
  2. Replies: 4
    Last Post: Jan 25, 2011, 10:39 AM
  3. [CLOSED] GridView script error
    By armadalabs in forum 1.x Premium Help
    Replies: 2
    Last Post: Dec 11, 2009, 7:49 AM
  4. Replies: 2
    Last Post: Jul 29, 2009, 1:57 PM
  5. row expander script error
    By [WP]joju in forum 1.x Help
    Replies: 9
    Last Post: Feb 12, 2009, 6:17 AM

Posting Permissions