[CLOSED] DirectEvent throwing error for controls creating at runtime

  1. #1

    [CLOSED] DirectEvent throwing error for controls creating at runtime

    Hi,

    I have created controls at runtime and adding DirectEvent to those controls. while running the form the error throwing like control not found. I am able to access those controls with DirectMethod, but it is not possible in all scenarios. So I need to resolve issue with DirectEvent. Please check the following code

    
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" 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">
        
        protected void Page_Load(object sender, EventArgs e)
        {
            //CheckLoadingFile();
        }
        public void CheckLoadingFile()
        {
            SortedList sLoansToOpen;
    
            if (Session["AppListToOpen"] != null)
            {
                sLoansToOpen = (SortedList)Session["AppListToOpen"];
                if (sLoansToOpen.Count > 0)
                {
                    LoadAppTabs();
                    pnlFooter.Show();
                    LoadToolTips();
                }
                else
                {
                    pnlFooter.Hide();
                }
            }
            else
            {
                pnlFooter.Hide();
            }
    
            vpCommonPage.DoLayout();
        }
    
        public void LoadToolTips()
        {
            SortedList sAppList;
            Ext.Net.ToolTip pnlTooltip;
            if (Session["AppListToOpen"] != null)
            {
                sAppList = (SortedList)Session["AppListToOpen"];
    
                for (int i = 0; i < sAppList.Count; i++)
                {
                    //if (Ext.Net.X.GetCmp("App" + sAppList.GetKey(i).ToString()) != null)
                    //{
                    pnlTooltip = new Ext.Net.ToolTip();
                    pnlTooltip.ID = "TTApp" + sAppList.GetKey(i).ToString();
                    //pnlTooltip.Target = "#{" + "App" + sAppList.GetKey(i).ToString() + "}.tabEl"; //pnlApp.ID;
                    pnlTooltip.Target = "App" + sAppList.GetKey(i).ToString() + ".tabEl"; //pnlApp.ID;
                    pnlTooltip.TrackMouse = true;
                    pnlTooltip.Html = "App" + sAppList.GetKey(i).ToString();
                    pnlTooltip.Anchor = "top";
                    //form1.Controls.Add(pnlTooltip); 
                    pnlTooltip.AddTo(form1);
                    //}
                }
            }
        }
    
        public void LoadAppTabs()
        {
            Ext.Net.Panel pnlApp;
    
            SortedList sAppList;
    
            tbApplications.RemoveAll();
    
            if (Session["AppListToOpen"] != null)
            {
                sAppList = (SortedList)Session["AppListToOpen"];
                
                for (int i = 0; i < sAppList.Count; i++)
                {
                    if (Ext.Net.X.GetCmp("App" + sAppList.GetKey(i).ToString()) == null)
                    {
                        pnlApp = new Ext.Net.Panel();
    
                        pnlApp.ID = "App" + sAppList.GetKey(i).ToString();
    
                        if (sAppList[sAppList.GetKey(i)].ToString().Trim().Length > 0)
                            pnlApp.Title = sAppList[sAppList.GetKey(i)].ToString();
                        else
                            pnlApp.Title = sAppList.GetKey(i).ToString();
    
                        pnlApp.Closable = true;
    
                        pnlApp.Listeners.Close.Handler = "CloseAppPanel('" + sAppList.GetKey(i).ToString() + "')";
                        //pnlApp.Listeners.Activate.Handler = "OpenLoanSpecifcPages('" + sAppList.GetKey(i).ToString() + "')";
                        pnlApp.DirectEvents.Activate.Event += pnlLoanTabs_Activate;
                        pnlApp.AddTo(tbApplications);
                    }
    
                }
    
                tbApplications.ActiveTabIndex = sAppList.IndexOfKey(sAppList.Count);
            }
        }
    
        public void pnlLoanTabs_Activate(object sender, DirectEventArgs e)
        {
    
        }
    
        public void btnAdd_Click(object sender, DirectEventArgs e)
        {
            SortedList sAppList;
            int keyVal;
            sAppList = (SortedList)Session["AppListToOpen"];
            if (sAppList == null)
                sAppList = new SortedList();
            keyVal = sAppList.Count;
            if (sAppList.Count > 0)
            {
                while (sAppList.ContainsKey(keyVal + 1))
                {
                    keyVal += 1;
                }
                sAppList.Add(keyVal + 1, "Panel " + (keyVal + 1));
            }
            else
                sAppList.Add(1, "Panel 1");
            Session["AppListToOpen"] = sAppList;
            CheckLoadingFile();
        }
    
        public void btnRemove_Click(object sender, DirectEventArgs e)
        {
            SortedList sAppList;
            sAppList = (SortedList)Session["AppListToOpen"];
            if (sAppList == null)
                sAppList = new SortedList();
            if (sAppList.Count > 0)
                sAppList.Remove(sAppList.Count);
            Session["AppListToOpen"] = sAppList;
            CheckLoadingFile();
        }
    
        [DirectMethod]
        public void pnlLoanTabsActivate(int appid)
        {
    
        }
    
        [DirectMethod]
        public void CloseApplication(string appid)
        {
            SortedList sAppList;
    
            if (Session["AppListToOpen"] != null)
            {
                sAppList = (SortedList)Session["AppListToOpen"];
    
                if (sAppList.ContainsKey(appid))
                {
                    sAppList.Remove(appid);
                    Session["AppListToOpen"] = sAppList;
                }
            }
            CheckLoadingFile();
        }
    
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
        <script type="text/javascript">
    
            var CloseAppPanel = function (appid) {
                //alert(appid);
                Ext.net.DirectMethods.CloseApplication(appid);
            }
    
            var OpenLoanSpecifcPages = function (appid) {
                //alert("Hi " + appid)
                Ext.net.DirectMethods.pnlLoanTabsActivate(appid);
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:Viewport runat="server" Layout="border" ID="vpCommonPage">
                <Items>
                    <ext:Panel ID="pnlMain" runat="server" Padding="5" Region="Center" BodyStyle="background-color:#DCEAFB">
                        <Items>
                            <ext:Button ID="btnAddPanel" Text="Add Panel" runat="server">
                                <DirectEvents>
                                    <Click OnEvent="btnAdd_Click">
                                    </Click>
                                </DirectEvents>
                            </ext:Button>
                            <ext:Button ID="btnRemovePanel" Text="Remove Panel" runat="server">
                                <DirectEvents>
                                    <Click OnEvent="btnRemove_Click">
                                    </Click>
                                </DirectEvents>
                            </ext:Button>
                        </Items>
                    </ext:Panel>
                    <ext:Panel ID="pnlFooter" runat="server" Region="South" Height="45" Margins="0,0,0,0"
                        Border="false">
                        <Items>
                            <ext:TabPanel ID="tbApplications" runat="server" Height="45" AnchorHorizontal="100%"
                                Border="false" IDMode="Explicit">
                                <Items>
                                </Items>
                            </ext:TabPanel>
                        </Items>
                    </ext:Panel>
                </Items>
            </ext:Viewport>
        </div>
        </form>
    </body>
    </html>
    Last edited by Daniil; May 31, 2011 at 10:45 AM. Reason: [CLOSED]
  2. #2
    Hi,

    DirectEvent requires a control instance on server side. To get it working you have to recreate a controls with DirectEvents during DirectEvent request also.

    Another solution - using DirectMethod instead of DirectEvent. DirectMethod doesn't require a control instance.
  3. #3

    DirectEvent throwing error for controls creating at runtime

    Hi Daniil,

    Yes, I just removed comments at page load, that means controls are recreating every time the page loads, even I got the same error like control not found and also another error like "this.dom.ParentNode" is null or not an object. Can you please check this code and correct me where I need to modify?

    Quote Originally Posted by Daniil View Post
    Hi,

    DirectEvent requires a control instance on server side. To get it working you have to recreate a controls with DirectEvents during DirectEvent request also.

    Another solution - using DirectMethod instead of DirectEvent. DirectMethod doesn't require a control instance.
  4. #4
    Well, the following code is to render a control:
    pnlTooltip.AddTo(form1);
    This doesn't add a control in any controls collection (for example, .Items and .Controls). So, it's absent on server side during DirectEvent.
  5. #5

    DirectEvent throwing error for controls creating at runtime

    Hi Daniil,

    I have removed all other irrelevant code along with tool tip functionality and verified the same again still it is throwing same error. Please check the simple code I have added here.

    
    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" 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">
       
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckLoadingFile();
        }
        public void CheckLoadingFile()
        {
            SortedList sLoansToOpen;
    
            if (Session["AppListToOpen"] != null)
            {
                sLoansToOpen = (SortedList)Session["AppListToOpen"];
                if (sLoansToOpen.Count > 0)
                {
                    LoadAppTabs();
                    pnlFooter.Show();
                }
                else
                {
                    pnlFooter.Hide();
                }
            }
            else
            {
                pnlFooter.Hide();
            }
    
            vpCommonPage.DoLayout();
        }
    
        public void LoadAppTabs()
        {
            Ext.Net.Panel pnlApp;
    
            SortedList sAppList;
    
            tbApplications.RemoveAll();
    
            if (Session["AppListToOpen"] != null)
            {
                sAppList = (SortedList)Session["AppListToOpen"];
                
                for (int i = 0; i < sAppList.Count; i++)
                {
                    if (Ext.Net.X.GetCmp("App" + sAppList.GetKey(i).ToString()) == null)
                    {
                        pnlApp = new Ext.Net.Panel();
    
                        pnlApp.ID = "App" + sAppList.GetKey(i).ToString();
    
                        if (sAppList[sAppList.GetKey(i)].ToString().Trim().Length > 0)
                            pnlApp.Title = sAppList[sAppList.GetKey(i)].ToString();
                        else
                            pnlApp.Title = sAppList.GetKey(i).ToString();
    
                        pnlApp.Closable = true;
    
                        pnlApp.Listeners.Close.Handler = "CloseAppPanel('" + sAppList.GetKey(i).ToString() + "')";
                        pnlApp.DirectEvents.Activate.Event += pnlLoanTabs_Activate;
                        pnlApp.AddTo(tbApplications);
                    }
                }
                tbApplications.ActiveTabIndex = sAppList.IndexOfKey(sAppList.Count);
            }
        }
    
        public void pnlLoanTabs_Activate(object sender, DirectEventArgs e)
        {
    
        }
    
        public void btnAdd_Click(object sender, DirectEventArgs e)
        {
            SortedList sAppList;
            int keyVal;
            sAppList = (SortedList)Session["AppListToOpen"];
            if (sAppList == null)
                sAppList = new SortedList();
            keyVal = sAppList.Count;
            if (sAppList.Count > 0)
            {
                while (sAppList.ContainsKey(keyVal + 1))
                {
                    keyVal += 1;
                }
                sAppList.Add(keyVal + 1, "Panel " + (keyVal + 1));
            }
            else
                sAppList.Add(1, "Panel 1");
            Session["AppListToOpen"] = sAppList;
            CheckLoadingFile();
        }
    
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title></title>
        <script type="text/javascript">
    
            var CloseAppPanel = function (appid) {
                //alert(appid);
                Ext.net.DirectMethods.CloseApplication(appid);
            }
    
            var OpenLoanSpecifcPages = function (appid) {
                //alert("Hi " + appid)
                Ext.net.DirectMethods.pnlLoanTabsActivate(appid);
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <ext:ResourceManager ID="ResourceManager1" runat="server" />
            <ext:Viewport runat="server" Layout="border" ID="vpCommonPage">
                <Items>
                    <ext:Panel ID="pnlMain" runat="server" Padding="5" Region="Center" BodyStyle="background-color:#DCEAFB">
                        <Items>
                            <ext:Button ID="btnAddPanel" Text="Add Panel" runat="server">
                                <DirectEvents>
                                    <Click OnEvent="btnAdd_Click">
                                    </Click>
                                </DirectEvents>
                            </ext:Button>
                        </Items>
                    </ext:Panel>
                    <ext:Panel ID="pnlFooter" runat="server" Region="South" Height="45" Margins="0,0,0,0"
                        Border="false">
                        <Items>
                            <ext:TabPanel ID="tbApplications" runat="server" Height="45" AnchorHorizontal="100%"
                                Border="false" IDMode="Explicit">
                                <Items>
                                </Items>
                            </ext:TabPanel>
                        </Items>
                    </ext:Panel>
                </Items>
            </ext:Viewport>
        </div>
        </form>
    </body>
    </html>
    Quote Originally Posted by Daniil View Post
    Well, the following code is to render a control:
    pnlTooltip.AddTo(form1);
    This doesn't add a control in any controls collection (for example, .Items and .Controls). So, it's absent on server side during DirectEvent.
  6. #6
    There is still the same problem I described.
    pnlApp.AddTo(tbApplications);
    Please replace with
    pnlApp.Items.Add(tbApplications);
  7. #7

    DirectEvent throwing error for controls creating at runtime

    Hi Daniil,

    I am not sure, but I think pnlApp.AddTo(tbApplications) means all pnlApp (tabs) will add to tbApplications (TabPanel) and pnlApp.items.Add(tbApplications) means add TabPanel to tab pnlApp. Is it right? Even though I tried both cases like pnlApp.Items.Add(tbApplications) and also tbApplications.Items.Add(pnlApp). This times nothing is showing up.


    Quote Originally Posted by Daniil View Post
    There is still the same problem I described.
    pnlApp.AddTo(tbApplications);
    Please replace with
    pnlApp.Items.Add(tbApplications);
  8. #8
    Yes, must be
    tbApplications.Items.Add(pnlApp)
    Apologize.

    I will try to clarify what happens.

    1. During initial Page_Load nothing happens because Session["AppListToOpen"] is null.

    2. Click on button "Add Panel"

    3. The whole page life cycle is executed.

    3.1. Including Page_Load - which is executed before DirectEvent handler. So, Session["AppListToOpen"] is still null.

    3.2. DirectEvent handler is executed and now Session["AppListToOpen"] is not null and a tab is added to TabPanel's .Items, but it doesn't force rendering of control during DirectEvent. So, nothing is rendered.

    I'd suggest you to investigate Asp.Net manuals, articles about dynamically creating controls.

    Why don't you want use DirectMethod instead DirectEvent?

Similar Threads

  1. [CLOSED] Creating DirectEvent from codebehind
    By krzak in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 01, 2011, 10:17 AM
  2. Replies: 6
    Last Post: Apr 07, 2010, 4:18 AM
  3. Replies: 2
    Last Post: Mar 02, 2010, 1:50 AM
  4. [CLOSED] creating more than one window at runtime
    By fabiomarcos in forum 1.x Help
    Replies: 2
    Last Post: Nov 27, 2008, 1:15 PM
  5. Creating GridPanel at runtime
    By methode in forum 1.x Legacy Premium Help
    Replies: 8
    Last Post: Oct 21, 2008, 12:39 PM

Tags for this Thread

Posting Permissions