[CLOSED] CardLayout and Ext.getCmp

  1. #1

    [CLOSED] CardLayout and Ext.getCmp

    The code below works fine in 2.5, but not in 4.1. Could you please take a look and tell me what would I need to change? Thank you!

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
       <title></title>
       <script type="text/javascript">
          function TestScript()
          {
             var test1 = Ext.getCmp("Container1");
             alert(test1.id);
          }
       </script>
       <script runat="server">
          protected void Page_Load( object sender, EventArgs e )
          {
             if ( !X.IsAjaxRequest )
             {
                storeConditionTypes.DataSource = Data;
                storeConditionTypes.DataBind();
             }
          }
    
          private object[] Data
          {
             get
             {
                return new object[]
                {
                    new object[] { 1, "Value 1" },
                    new object[] { 2, "Value 2" },
                    new object[] { 3, "Value 3" },
                    new object[] { 4, "Value 4" },
                    new object[] { 5, "Value 5" }
                };
             }
          }
       </script>
    </head>
    <body>
       <form id="form1" runat="server">
          <ext:ResourceManager ID="rscManager" runat="server" />
          <ext:SelectBox runat="server" ID="SelectBox1" FieldLabel="SelectBox1" ValueField="ID" DisplayField="Description">
             <Store>
                <ext:Store runat="server" ID="storeConditionTypes">
                   <Model>
                      <ext:Model runat="server" IDProperty="ID">
                         <Fields>
                            <ext:ModelField Name="ID" Type="Int"></ext:ModelField>
                            <ext:ModelField Name="Description" Type="String"></ext:ModelField>
                         </Fields>
                      </ext:Model>
                   </Model>
                </ext:Store>
             </Store>
             <SelectedItems>
                <ext:ListItem Index="0" />
             </SelectedItems>
             <Listeners>
                <Change Handler="TestScript();" />
             </Listeners>
          </ext:SelectBox>
          <ext:Container runat="server" ID="Container1" ActiveIndex="0">
             <LayoutConfig>
                <ext:CardLayoutConfig DeferredRender="false" />
             </LayoutConfig>
             <Items>
                <ext:TextField runat="server" ID="TextField1" />
                <ext:TextField runat="server" ID="TextField2" />
                <ext:TextField runat="server" ID="TextField3" />
                <ext:TextField runat="server" ID="TextField4" />
                <ext:TextField runat="server" ID="TextField5" />
             </Items>
          </ext:Container>
       </form>
    </body>
    </html>
    Last edited by fabricio.murta; Oct 29, 2016 at 9:01 PM.
  2. #2
    Hello Edgar!

    This error happens because the databind() called in code behind + page load makes the change event trigger before the Container1 container is drawn. You probably should use a proxy/loader on your store to avoid this race condition.

    Alternatively, just define the container before (above) the selectbox block, and it also should work fine.

    Hope this helps!
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Thanks FabrÃ*cio! It did help.
  4. #4
    Thanks for the feedback and simple runnable code sample!

    Just to perfect your provided sample codes even more, would you mind including the <%@ Page Language="C#" %> header, <%@ using Namespace=... %> (if namespaces needed in <script runat="server"> blocks), and the using <namespace>; (of course where it applies) in future inquiries?

    I believe it can also be easier for you, as all you would have to do on your side would be ctrl+a then ctrl+v on the forum thread. :)
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Replies: 1
    Last Post: May 18, 2016, 5:45 AM
  2. [CLOSED] App vrs getCmp
    By Z in forum 3.x Legacy Premium Help
    Replies: 1
    Last Post: Aug 10, 2015, 9:16 PM
  3. X.GetCmp and FileUploadField
    By josecano in forum 1.x Help
    Replies: 2
    Last Post: May 01, 2013, 7:56 AM
  4. Ext.getCmp() not working in UserControl
    By ontiv in forum 2.x Help
    Replies: 10
    Last Post: Oct 16, 2012, 7:54 AM
  5. [CLOSED] CardLayout rendering ALL panel contents at once AND OUTSIDE the CardLayout?
    By juanpablo.belli@huddle.com.ar in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Feb 26, 2009, 3:08 PM

Posting Permissions