[CLOSED] Problem with load dynamic user control in tabpanel

  1. #1

    [CLOSED] Problem with load dynamic user control in tabpanel

    Hi,
    see my example, when I create the usercontrol, if I use a public method of usercontrol I take an error of undefined object in the script, because the script generated by public method is run before the object is created.
    Please help me.
    Thank you

    Jimmy

    page
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="UCDynamic.aspx.cs" Inherits="Test.UCDynamic" %>
    
    
    <!DOCTYPE html>
    
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        
            <ext:ResourceManager runat="server" />
    
    
            <ext:TabPanel ID="tbp" runat="server" Width="700" Height="500">
                <Items>
                    <ext:Panel ID="pnl1" runat="server" Width="700" Height="500" Title="Panel 1">
                        <Items>
                            <ext:Label ID="lbl1" runat="server" Text="label label label" />
                        </Items>
                    </ext:Panel>
                    <ext:Panel ID="pnl2" runat="server" Width="700" Height="500" Title="Panel 2">
                    </ext:Panel>
                </Items>
                <DirectEvents>
                    <TabChange OnEvent="tbp_TabChange">
                        <EventMask ShowMask="true" />
                    </TabChange>
                </DirectEvents>
            </ext:TabPanel>
    
    
        </form>
    </body>
    </html>
    .cs of page
    using Ext.Net;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    
    namespace Test
    {
        public partial class UCDynamic : System.Web.UI.Page
        {
            UCCombo ucCombo;
    
    
            protected void Page_Load(object sender, EventArgs e)
            {
    
    
            }
    
    
            protected void tbp_TabChange(object sender, DirectEventArgs e)
            {
                if (string.Compare((sender as Ext.Net.TabPanel).ActiveTab.ID, "pnl2", true) == 0)
                {
                    List<SBRow> values = new List<SBRow>();
    
    
                    for (int i = 0; i < 5; i++)
                        values.Add(new SBRow() { idValue = i.ToString(), description = string.Format("Value {0}", i.ToString()) });
    
    
                    ucCombo = (UCCombo)this.LoadControl("UCCombo.ascx");
    
    
                    ucCombo.ID = "userCtrlUcCombo";
    
    
                    pnl2.ContentControls.Clear();
    
    
                    ucCombo.LoadSbBox(values);
    
    
                    pnl2.ContentControls.Add(ucCombo);
    
    
                    pnl2.UpdateContent();
    
    
                    pnl2.UpdateLayout();
                }
            }
        }
    }
    .ascx
    <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="UCCombo.ascx.cs" Inherits="Test.UCCombo" %>
    
    
    <ext:Panel ID="pnlCtrl" runat="server" Width="700" Height="500">
        <Items>
            <ext:SelectBox ID="sbBox" ClientIDMode="Static" runat="server"
                TypeAhead="true"
                ForceSelection="true"
                SelectOnFocus="false"
                TriggerAction="All"
                Width="300"
                ValueField="idValue"
                DisplayField="description">
                <Store>
                    <ext:Store ID="stSbBox" runat="server">
                        <Model>
                            <ext:Model ID="modelSbBox" runat="server">
                                <Fields>
                                    <ext:ModelField Name="idValue" />
                                    <ext:ModelField Name="description" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
            </ext:SelectBox> 
        </Items>
    </ext:Panel>
    .cs of ascx
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    
    namespace Test
    {
        public partial class UCCombo : System.Web.UI.UserControl
        {
            protected void Page_Load(object sender, EventArgs e)
            {
    
    
            }
    
    
            public void LoadSbBox(List<SBRow> values)
            {
                this.stSbBox.DataSource = values;
                this.stSbBox.DataBind();
            }
        }
    
    
        public class SBRow
        {
            public string idValue;
            public string description;
        }
    }
    Last edited by fabricio.murta; Jan 03, 2017 at 9:52 PM. Reason: no user feedback for 7+ days
  2. #2
    Hello xeo4.it!

    I couldn't run your test case even if I merge all controls and classes in a single page application. Can you review it? Maybe replicate the select box with a static one with the values in the main page, so we can compare the results with a working static component the way you wanted the other select box to be displayed?
    Fabrício Murta
    Developer & Support Expert
  3. #3
    Hello Fabricio,
    I modified the code to make it fit in a page and in an .ascx file, but the .ascx file is needed.
    I can not use static components because I need this type of code, of course, my example is simple but my real code is more complex.

    Jimmy

    <%@ Page Language="C#" %>
    
    
    <%@ Import Namespace="System.Collections.Generic"%>
    <%@ Import Namespace="Ext.Net.Examples"%>
    
    
    <script runat="server">
        UserControl currentUC;
    
    
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }
    
    
        
        protected void tbp_TabChange(object sender, DirectEventArgs e)
            {
                if (string.Compare((sender as Ext.Net.TabPanel).ActiveTab.ID, "pnl2", true) == 0)
                {
                    currentUC = (UserControl)this.LoadControl("UCCombo2.ascx");
    
    
                    currentUC.ID = "userCtrlUcCombo";
    
    
                    pnl2.ContentControls.Clear();
    
    
                    pnl2.ContentControls.Add(currentUC);
    
    
                    pnl2.UpdateContent();
    
    
                    pnl2.UpdateLayout();
                }
            }
    
    
        
    </script>
    
    
    <!DOCTYPE html>
    
    
    <html>
    <head runat="server">
        <title>Update Controls and Content during a DirectEvent - Ext.NET Examples</title>
        <link href="/resources/css/examples.css" rel="stylesheet" />
    </head>
    <body>
        <form runat="server">
            <ext:ResourceManager runat="server" />
    
    
            <ext:TabPanel ID="tbp" runat="server" Width="700" Height="500">
                <Items>
                    <ext:Panel ID="pnl1" runat="server" Width="700" Height="500" Title="Panel 1">
                        <Items>
                            <ext:Label ID="lbl1" runat="server" Text="label label label" />
                        </Items>
                    </ext:Panel>
                    <ext:Panel ID="pnl2" runat="server" Width="700" Height="500" Title="Panel 2">
                    </ext:Panel>
                </Items>
                <DirectEvents>
                    <TabChange OnEvent="tbp_TabChange">
                        <EventMask ShowMask="true" />
                    </TabChange>
                </DirectEvents>
            </ext:TabPanel>
        </form>
    </body>
    </html>
    .ascx file : "UCCombo2.ascx"
    <%@ Control Language="C#" %>
    
    
    <script runat="server">
        protected void Page_Load(object sender, EventArgs e)
        {
        
           List<SBRow> values = new List<SBRow>();
    
    
            for (int i = 0; i < 5; i++)
                values.Add(new SBRow() { idValue = i.ToString(), description = string.Format("Value {0}", i.ToString()) });    
    
    
            this.stSbBox.DataSource = values;
            this.stSbBox.DataBind();
        }   
    
    
        public class SBRow
        {
            public string idValue;
            public string description;
        }
         
    </script>
    
    
    <ext:Panel ID="pnlCtrl" runat="server" Width="700" Height="500">
        <Items>
            <ext:SelectBox ID="sbBox" ClientIDMode="Static" runat="server"
                TypeAhead="true"
                ForceSelection="true"
                SelectOnFocus="false"
                TriggerAction="All"
                Width="300"
                ValueField="idValue"
                DisplayField="description">
                <Store>
                    <ext:Store ID="stSbBox" runat="server">
                        <Model>
                            <ext:Model ID="modelSbBox" runat="server">
                                <Fields>
                                    <ext:ModelField Name="idValue" />
                                    <ext:ModelField Name="description" />
                                </Fields>
                            </ext:Model>
                        </Model>
                    </ext:Store>
                </Store>
            </ext:SelectBox> 
        </Items>
    </ext:Panel>
  4. #4
    Hello Jimmy!

    Check if this helps, in your aspx page, change the sequence to add the component to this:

    currentUC.ID = "userCtrlUcCombo";
    pnl2.ContentControls.Clear();
                
    // Adds the component, preparing the page scope for it.
    pnl2.ContentControls.Add(currentUC);
    pnl2.UpdateContent();
    
    // Queues the load data commands
    currentUC.LoadSbBox(values);
    
    // Flush the queued scripts now
    pnl2.ResourceManager.AddScript(pnl2.ContentToScript());
                
    // Continue to whatever we want to do.
    pnl2.UpdateLayout();
    Let me know if it does not help you at all!
    Fabrício Murta
    Developer & Support Expert
  5. #5
    Hello Jimmy!

    It's been a considerable time since we last replied this thread and we didn't receive any feedback from you until now. Did the above help you out, was you able to have your case working? We're looking forward for your feedback!
    Fabrício Murta
    Developer & Support Expert

Similar Threads

  1. Replies: 1
    Last Post: Jan 26, 2015, 3:42 PM
  2. [CLOSED] User Control Render dynamic value assign issue in page load
    By shaileshsakaria in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 26, 2014, 5:19 PM
  3. Replies: 6
    Last Post: May 30, 2013, 5:49 AM
  4. Replies: 2
    Last Post: Feb 06, 2012, 9:06 AM
  5. [CLOSED] Problem on dynamic load user control
    By andreasperanza in forum 1.x Legacy Premium Help
    Replies: 13
    Last Post: Dec 22, 2011, 4:23 PM

Posting Permissions