2.2 - Store name is undefined when ascx is loaded

Page 2 of 2 FirstFirst 12
  1. #11
    Not sure if my observation is related or not, especially since this is for Ext.NET 2.1.1:

    I noticed that when I attempt to render a Panel with a UserControl, the JSON that comes out is reversed.
    So I would see function calls on various controls before they are actually defined.
    It would result in similar errors with stuff not being defined.

    Now if I would replace the Panel with a FormPanel, the JSON would be generated in the proper order.

    I thought this was some sort of limitation with Panel so I didn't bother reporting it...
    Last edited by ltctech; Apr 21, 2013 at 9:46 PM.
  2. #12
    vladimir

    i still didnt understand what i need to recreate. I have no postbacks on my code.
  3. #13
    It doesn't matter postback or ajax request, in any way it is request to the page
    You have direct event (ajax request to the page) from the store, store is absent on server side because you did not recreate it
  4. #14
    RefreshData is a DirectEvent executed during a Postback.

    You need to recreate dynamic controls with same ID during a postback.
    You can do this by storing the List of IDs serialized in a hidden field, deserializing this hidden field on Page_Load and recreating them.
    You should be giving an ID to your user controls, if you have multiple instances just do something like cont.ID = "uc" + Guid.NewGuid();.

    If you don't want to recreate dynamics controls, you should use an HTTP Handler or Web Service to populate the store.
  5. #15
    and how can i recreate since everything is on my ascx file?? there is no codebehind on my usercontrol.

    any samples pls?
  6. #16
    This is how my dynamic tab panel is implemented:

    testuctabs.aspx
    <%@ Page Language="C#" AutoEventWireup="true" %>
    
    <%@ Register Src="~/testuctab.ascx" TagName="TestTab" TagPrefix="cstm" %>
    
    <!DOCTYPE html>
    
    <script runat="server">
    
        private class TestucTab
        {
            public testuctab_ascx Testuc { get; set; }
            public FormPanel Tab { get; set; }
        }
    
        private List<Guid> CurrentTabIDs
        {
            get { return !string.IsNullOrWhiteSpace(hidCurrTabIDs.Text) ? JSON.Deserialize<List<Guid>>(hidCurrTabIDs.Text) : new List<Guid>(); }
            set { hidCurrTabIDs.Text = JSON.Serialize(value); }
        }
    
        protected void Page_Load(object sender, EventArgs e)
        {
            CurrentTabIDs.ForEach(x => CreateTabControls(x));
        }
    
        private TestucTab CreateTabControls(Guid tabID)
        {
            FormPanel tab = new FormPanel();
            tab.Layout = "FormLayout";
            string cID = string.Format("tab{0:N}", tabID);
            tab.ID = cID;
            tab.Title = cID;
            tp.Items.Add(tab);
    
            testuctab_ascx testuc = (testuctab_ascx)this.LoadControl(@"~/testuctab.ascx");
            testuc.ID = string.Format("testuc{0:N}", tabID);
            tab.ContentControls.Add(testuc);
            return new TestucTab() { Testuc = testuc, Tab = tab };
        }
    
        private void CreateTab()
        {
            Guid newtabID = Guid.NewGuid();
    
            List<Guid> tabIDs = CurrentTabIDs;
            tabIDs.Add(newtabID);
            CurrentTabIDs = tabIDs;
    
            TestucTab testucTab = CreateTabControls(newtabID);
    
            X.ControlsScripting = false;
    
            testucTab.Testuc.initStuff("Setting this from parent");
    
            X.ControlsScripting = true;
    
            testucTab.Tab.Render();
            tp.SetActiveTab(testucTab.Tab);
        }
        
        protected void btnLoadControl_DirectClick(object sender, DirectEventArgs e)
        {
            CreateTab();
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>UserControl Loading Test</title>
    </head>
    <body>
        <form id="frm" runat="server">
    
            <ext:ResourceManager ID="rsMan" runat="server" />
    
            <ext:Button ID="btnLoadControl" runat="server" OnDirectClick="btnLoadControl_DirectClick" Text="Create Tab" />
    
            <ext:TabPanel ID="tp" runat="server" Layout="FitLayout" />
    
            <ext:Hidden ID="hidCurrTabIDs" runat="server" />
    
        </form>
    </body>
    </html>
    testuctab.ascx
    <%@ Control Language="C#" AutoEventWireup="true" %>
    
    <script runat="server">
    
        public class State
        {
            public string StateID { get; set; }
            public string StateName { get; set; }
        }
    
        public void initStuff(string text)
        {
            lbl.Text = text;
    
            strStateList.DataSource = new List<State>() 
                { 
                    new State(){ StateID = "AK", StateName="ALASKA" },
                    new State(){ StateID = "AL", StateName="ALABAMA" },
                    new State(){ StateID = "AR", StateName="ARKANSAS" }
                };
        }
    
        protected void btn_DirectClick(object sender, DirectEventArgs e)
        {
            lbl.Text = DateTime.Now.ToString();
            cmbState.Value = "AL";
        }
    </script>
    <ext:FormPanel runat="server" Layout="FormLayout" Height="200">
        <Items>
    
            <ext:Label runat="server" ID="lbl" />
    
            <ext:ComboBox runat="server" ID="cmbState" DisplayField="StateName" ValueField="StateID">
                <Store>
                    <ext:Store ID="strStateList" runat="server">
                        <Reader>
                            <ext:JsonReader />
                        </Reader>
                        <Model>
                            <ext:Model ID="mdlStateList" runat="server" IDProperty="StateID">
                                <Fields>
                                    <ext:ModelField Name="StateID" />
                                    <ext:ModelField Name="StateName" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
            </ext:ComboBox>
    
            <ext:Button ID="btn" runat="server" Text="Do Stuff" OnDirectClick="btn_DirectClick" />
    
        </Items>
    </ext:FormPanel>
    Last edited by ltctech; Apr 22, 2013 at 6:33 AM.
  7. #17
    amazing man!! i i add and test some more features to fill my demand.

    for a while everything worked like a charm, but i didnt understand full code yet.

    Whats X.ControlsScripting = false; does??
  8. #18
    See this thread:
    http://forums.ext.net/showthread.php...ia-DirectEvent

    In short, when you call component.Render() it generates JavaScript that defines the various Ext JS controls.
    When you modify a property on a component during Postback e.g. lbl.Text = "test"; it generates lbl.setText('test') in JavaScript.
    This is redundant as the control was already defined with the text properly set during render.
    So in order to prevent redundant script generation during Postback when you are rendering controls you turn off Control Scripting.
    This is exactly what X.ControlsScripting does.

    They really need to provide a proper example and properly document X.ControlsScripting functionality.
Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 1
    Last Post: Apr 02, 2013, 5:03 AM
  2. [CLOSED] Difference Store behaviour Usercontrol (.ASCX) vs Class (.CS)
    By pschojer in forum 1.x Legacy Premium Help
    Replies: 5
    Last Post: Apr 18, 2012, 3:51 PM
  3. Replies: 2
    Last Post: Apr 10, 2012, 12:08 PM
  4. Store is undefined
    By roszman in forum 1.x Help
    Replies: 10
    Last Post: May 26, 2010, 9:26 AM
  5. Replies: 1
    Last Post: Feb 24, 2010, 3:05 PM

Tags for this Thread

Posting Permissions