[CLOSED] Close windows on click in UserControl loaded dynamically

  1. #1

    [CLOSED] Close windows on click in UserControl loaded dynamically

    I have this code:

    WebForm1.aspx
    <%@ Page Language="vb" %>
    
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    
    <script runat="server">
        Protected Sub Page_Load(sender As Object, e As EventArgs)
            Dim Applicazione As New Ext.Net.UserControlLoader
            Applicazione.ID = "Applicazione1"
            Applicazione.Path = "WebUserControl1.ascx"
            PanelApplicazione.Items.Clear()
            PanelApplicazione.Items.Add(Applicazione)
        End Sub
    </script>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
    
        <ext:ResourceManager runat="server" ID="ResourceManager1" />
    
        <ext:Viewport runat="server" ID="Viewport1">
            <LayoutConfig>
                <ext:VBoxLayoutConfig Align="Center" />
            </LayoutConfig>
    
            <Items>
                <ext:Panel ID="PanelApplicazione" runat="server" Flex="1" Width="1000" Border="false" PaddingSpec="5 0 5 0" Layout="FitLayout" />
            </Items>
    
        </ext:Viewport>
    
        </form>
    </body>
    </html>
    WebUserControl1.ascx
    <%@ Control Language="vb" %>
    
    <script runat="server">
        Protected Sub Button1_Click(sender As Object, e As Ext.Net.DirectEventArgs)
            Windows1.Show()
        End Sub
    </script>
    
    <ext:Panel ID="Panel1" runat="server">
        <Items>
            <ext:Button runat="server" ID="Button1" Text="GO !" OnDirectClick="Button1_Click" />
        </Items>
    </ext:Panel>
    
    <ext:Window runat="server" ID="Windows1" Hidden="true" >
        <Items>
            <ext:UserControlLoader Path="test.ascx" runat="server" ID="UserControlLoaderTest" />
        </Items>
    </ext:Window>
    Test.ascx
    <%@ Control Language="vb" %>
    <script runat="server">
        Protected Sub Button2_DirectClick(sender As Object, e As DirectEventArgs)
            CType(Ext.Net.X.GetCtl(Me.Parent.Parent.ID), Ext.Net.Window).Hide()
        End Sub
    </script>
    
    
    <ext:Panel ID="Panel1" runat="server" >
        <Items>
            <ext:Button runat="server" ID="Button2" Text="CHIUDI" OnDirectClick="Button2_DirectClick" />
        </Items>
    </ext:Panel>
    that work perfectly:
    If you click on "Go !" button and on "CHIUDI" button... the window closes without any problems.

    BUT...
    If you change the code for load User Control dinamically.....

    WebUserControl1.ascx
    <%@ Control Language="vb" %>
    
    <script runat="server">
        Protected Sub Button1_Click(sender As Object, e As Ext.Net.DirectEventArgs)
            Dim Controllo As New Ext.Net.UserControlLoader
            Controllo.ID = "Test1"
            Controllo.Path = "Test.ascx"
    
            Dim Finestra As New Ext.Net.Window
            Finestra.ID = "FinestraTest1"
            Finestra.Items.Add(Controllo)
    
            Finestra.Render()
        End Sub
    </script>
    
    <ext:Panel ID="Panel1" runat="server">
        <Items>
            <ext:Button runat="server" ID="Button1" Text="GO !" OnDirectClick="Button1_Click" />
        </Items>
    </ext:Panel>
    ...appears "The control with ID 'ctl03_Button2' not found" error.
    I tried to play with the properties "ClientIDMode" and "IDMode", without success.

    Help, please.
    Last edited by Daniil; Dec 23, 2014 at 5:31 PM. Reason: [CLOSED]
  2. #2
    Hi Mario,

    .GetCtl() searches real control on server side. If you create a control dynamically and don't recreate it on a request, then .GetCtl() cannot find a control, because it is just absent.

    Please try to use .GetCmp<>() instead.
  3. #3
    Hi Danill,

    I have replaced

    <script runat="server">
        Protected Sub Button2_DirectClick(sender As Object, e As DirectEventArgs)
            CType(Ext.Net.X.GetCtl(Me.Parent.Parent.ID), Ext.Net.Window).Hide()
        End Sub
    </script>
    with

    <script runat="server">
        Protected Sub Button2_DirectClick(sender As Object, e As DirectEventArgs)
            CType(Ext.Net.X.GetCmp(Me.Parent.Parent.ID), Ext.Net.Window).Hide()
        End Sub
    </script>
    but not works.... :(
  4. #4
    I guess this
    Me.Parent.Parent.ID
    doesn't reflect the Window's ID.

    What is the value there?
  5. #5
    Danill,

    I believe that the problem is still before ...

    the code returns this error:
    The control with ID 'ctl03_Button2' not found
    Maybe first you need to solve this problem.
    Last edited by geoffrey.mcgill; Dec 15, 2014 at 12:35 PM.
  6. #6
  7. #7
    Hello Danill,

    I read carefully the two links you posted ... without being able to solve my problem.

    Can you please tell me directly the solution to be able to call up the sub "Button2_DirectClick" contained in Test.ascx ?
  8. #8
    If you want to use DirectEvent, then you should recreate user controls on each request. There is an example.
    https://examples2.ext.net/#/XRender/...UpdateContent/

    Please notice this code.
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrWhiteSpace(CurrentControl.Text))
        {
            this.LoadUserControl(CurrentControl.Text);
        }
    }
    If the user control has been already loaded, it is recreated on each request.

    Investigating/reading this thread might be also very helpful.
    http://forums.ext.net/showthread.php?27618

Similar Threads

  1. How to close windows from a child iFrame button?
    By metallica87 in forum 2.x Help
    Replies: 2
    Last Post: Nov 14, 2012, 4:30 AM
  2. [CLOSED] Managing events from a dynamically loaded UserControl
    By egvt in forum 1.x Legacy Premium Help
    Replies: 4
    Last Post: Feb 20, 2012, 4:49 PM
  3. Replies: 3
    Last Post: Mar 30, 2010, 1:03 PM
  4. Replies: 0
    Last Post: Jan 08, 2009, 11:31 AM
  5. HOW DO ON CLICK CLOSE A WINDOWS
    By wkcode in forum 1.x Help
    Replies: 1
    Last Post: Oct 14, 2008, 12:45 PM

Tags for this Thread

Posting Permissions