[CLOSED] Loading usercontrol with only the path (usercontrol contains ext.window inside)

  1. #1

    [CLOSED] Loading usercontrol with only the path (usercontrol contains ext.window inside)

    Hi

    I´m creating a reusable GridPanel, where I set the SQL query and path to usercontrol for the maintenance of records (add and edit)...

    What I need is load my usercontrol with just the path for this usercontrol.

    My usercontrol has a ext.window inside with 'ok' and 'cancel' buttons. When the 'ok' button is clicked, I want update my GridPanel.

    Thanks for any help!
    Last edited by Daniil; Feb 14, 2012 at 7:08 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Could you concretize the questions? How do you try? What problems are you facing?

    As well, I'm not sure that I understand the following well:
    What I need is load my usercontrol with just the path for this usercontrol.
    Please clarify.
  3. #3
    Hi Danill!

    I created an example to demonstrate what I need.

    I can load the UC1 and UC2 only with the path (The path to the UserControls is in combobox).

    But the UC3 (which contains a ext.Window) I can not load using ext: UserControlLoader.

    The only way that I'm able to load the UC3 is registering the usercontrol on page (see 'Load UC3' button) but this I do not want.

    I want to load the UC3 with only the path, how I do with the UC1 and UC2. (but not inside the TabPanel).

    I would also like to delegate a function to the UC3 to refresh the page that loaded the UC3.

    Main Page
    <%@ Page Language="vb" AutoEventWireup="false" CodeBehind="test3.aspx.vb" Inherits="SuperaWeb.test3" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Register src="uc3.ascx" tagname="uc3" tagprefix="myOwnUC" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">    
        
        Protected Sub LoadUserControl(sender As Object, e As DirectEventArgs)
            Dim ucl As UserControlLoader = New UserControlLoader()
            Dim p As Ext.Net.Panel
            
            ucl.Path = cmbUC.SelectedItem.Text
            ucl.UserControlID = "UC_" & CStr(Rnd() * 1000000000000000.0)
            p = New Ext.Net.Panel(cmbUC.SelectedItem.Text)
            p.Closable = True
            p.Items.Add(ucl)
            TabPanel1.Items.Add(p)
            p.Render()
            
        End Sub
            
        Protected Sub LoadUC3(sender As Object, e As DirectEventArgs)
            
            UC3.Start()
            
        End Sub
        
    </script> 
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <ext:ResourceManager ID="ResourceManager1" runat="server" />   
            
            <ext:TabPanel ID="TabPanel1" runat="server" Width="300" Height="300" />
                 
            <ext:ComboBox runat="server" ID="cmbUC">
                <Items>
                    <ext:ListItem Text="UC1.ascx" Value="UC1.ascx" />
                    <ext:ListItem Text="UC2.ascx" Value="UC2.ascx" />
                    <ext:ListItem Text="UC3.ascx" Value="UC3.ascx" />
                </Items>
                <SelectedItems>
                    <ext:ListItem Text="UC1.ascx" Value="UC1.ascx" />
                </SelectedItems>
            </ext:ComboBox>
    
            <ext:Button ID="Button1" runat="server" Text="Load UserControl" OnDirectClick="LoadUserControl" />   
            <ext:Button ID="Button2" runat="server" Text="Load UC3" OnDirectClick="LoadUC3" />
    
            <myOwnUC:uc3 ID="UC3" runat="server" />
    
        </div>
        </form>
    </body>
    </html>
    UC1.asx
    <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="UC1.ascx.vb" Inherits="SuperaWeb.UC1" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <ext:Panel runat="server" ID="pane1" Layout="FitLayout" Flex="1">
        <Items>
            <ext:Label runat="server" ID="lbl1" Text="Hello from UC1!" />
        </Items>
    </ext:Panel>
    uc2.ascx
    <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="UC2.ascx.vb" Inherits="SuperaWeb.UC2" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <script runat="server">
    
        Protected Sub StoreExplorerWebTab_Refresh(sender As Object, e As StoreRefreshDataEventArgs)
            'Me.storeExplorerWebTab.DataSource = Me.GetData()
            'Me.storeExplorerWebTab.DataBind()
        End Sub
        
    </script>
    
    <ext:Panel runat="server" ID="pane2" Layout="FitLayout" Flex="1">
        <Items>
            <ext:Label runat="server" ID="lbl2" Text="Hello from UC2!" />
        </Items>
    uc3.ascx
    <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="uc3.ascx.vb" Inherits="SuperaWeb.uc3" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <ext:Window 
        ID="wndEmpresasSGE" 
        runat="server"
        Icon="UserAdd"
        Title="Cadastro de Empresas"
        Width="680" 
        Height="530" 
        AutoShow="false" 
        Modal="true" 
        Resizable="false"
        Hidden="true"
        ButtonAlign="Right"
        Layout="FitLayout"
        DefaultButton="button[text=Ok]">
        <Items>
        <ext:Panel ID="pane3" runat="server" BodyStyle="background-color: #f9f9f9" BodyPadding="6" Layout="FitLayout" Border="true" Flex="1"> 
            <TopBar>
                <ext:Toolbar ID="tb3" runat="server">
                    <Items>
                        <ext:Button ID="btnAdd" runat="server" Icon="ApplicationAdd" Text="Add" 
                            ToolTip="Adicionar registro" Disabled="true" />
                        <ext:Button ID="btnEdit" runat="server" Icon="ApplicationEdit" Text="Edit" 
                            ToolTip="Editar registro selecionado" Disabled="true" />
                        <ext:Button ID="btnDelete" runat="server" Icon="ApplicationDelete" 
                            Text="Excluir" ToolTip="Deletar registro(s) selecionados" Disabled="true" />
                        <ext:Button ID="btnFind" runat="server" Icon="Find" Text="Find" 
                            ToolTip="Localizar registro"  Disabled="true" />
                        <ext:ToolbarSeparator ID="ctl133" runat="server" />
                        <ext:Button ID="btnPrint" runat="server" Icon="Printer" Text="Print" 
                            ToolTip="Imprimir registros" Disabled="true" />
                        <ext:Button ID="btnPrintPreview" runat="server" Icon="PrinterGo" 
                            Text="Preview" ToolTip="Visualizar impressão registros" Disabled="true" />
                        <ext:ToolbarSeparator ID="ToolbarSeparator1" runat="server" />
                        <ext:SplitButton ID="btnExport" runat="server" Icon="PageExcel" Text="Export" 
                            ToolTip="Export records to..." Disabled="true">
                            <menu>
                                <ext:Menu runat="server" ID="ctl394">
                                    <Items>
                                        <ext:MenuItem ID="mnuExportToExcel" runat="server" icon="PageExcel" 
                                            Text="Excel" />
                                        <ext:MenuItem ID="mnuExportToPdf" runat="server" icon="PageWhiteAcrobat" 
                                            Text="PDF" />
                                        <ext:MenuItem ID="mnuExportToXml" runat="server" icon="PageCode" Text="Xml" />
                                        <ext:MenuItem ID="mnuExportToText" runat="server" icon="PageWhite" 
                                            Text="Text" />
                                        <ext:MenuItem ID="mnuExportToHtml" runat="server" icon="Html" Text="Html" />
                                    </Items>
                                </ext:Menu>
                            </menu>
                        </ext:SplitButton>
                        <ext:ToolbarFill ID="ctl402" />
                        <ext:ComboBox ID="cmbQueries" runat="server" FieldLabel="Consultas" 
                            LabelWidth="60" Disabled="true">
                        </ext:ComboBox>
                    </Items>
                </ext:Toolbar>
            </TopBar>
            <Items>
                <ext:Label runat="server" ID="lbl3" Text="Hello From UC3 in ext:Window!" />
            </Items>
        </ext:Panel>
        </Items>
    </ext:Window>
    uc3 code behind
    Public Class uc3
        Inherits System.Web.UI.UserControl
    
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    
        End Sub
    
        Public Sub Start()
            wndEmpresasSGE.Show()
        End Sub
    
    End Class
  4. #4
    This might look something like this.

    Example C#
    protected void LoadUC3(object sender, DirectEventArgs e)
    {
        UserControlLoader ucl = new UserControlLoader();
        ucl.Path = "TestUC.ascx";
        this.Form.Controls.Add(ucl);
        ucl.Render();
        (ucl.UserControls[0] as TestUC).Start();
    }
    TestUC.ascx is the user control with Window. The "TestUC" is the class name of that user control.
  5. #5
    Hi Daniil...

    I made the changes you suggested ...
    The ext.window opens... but it does not close when I click in close button of window (x).

    My code looks like this:

        Protected Sub LoadUserControl(sender As Object, e As DirectEventArgs)
            
            Dim ucl As UserControlLoader = New UserControlLoader()
            
            ucl.Path = cmbUC.SelectedItem.Text
            ucl.UserControlID = "UC_" & CStr(Rnd() * 1000000000000000.0)
            Me.Form.Controls.Add(ucl)
            ucl.Render()
            DirectCast(ucl.UserControls(0), SuperaWeb.uc3).Start()
            
        End Sub
  6. #6
    I guess it's closed on the first attempt, but not close on the second one or further, right?

    I think it's an id conflict.

    I've just tried your code and the following
    ucl.UserControlID = "UC_" & CStr(Rnd() * 1000000000000000.0)
    produced 2 same ids of 3 (!).

    You should change this policy, I mean producing random ids.
  7. #7
    Hi Daniil ...

    you're right!

    I use now System.Ramdom.Next to generate UserControlID. It´s working.

    Thanks a lot...

    Now, I need get a return of my usercontrol. this return 'say' if I need refresh my GridPanel.

    It has an easy example of how I could do this?
  8. #8
    I think it would be best to start a new forum thread since the initial question has been answered (in the thread's title).
  9. #9
    Ok, no problem

    Thanks a lot for answer this question!

Similar Threads

  1. Replies: 1
    Last Post: May 29, 2013, 6:00 PM
  2. Replies: 0
    Last Post: Aug 03, 2011, 10:27 PM
  3. [CLOSED] Loading UserControl window from Parent Form throwing error
    By rnachman in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Mar 10, 2011, 3:43 PM
  4. [CLOSED] Trouble with loading usercontrol
    By smart+ in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 05, 2010, 6:32 PM
  5. Help with UserControl inside window
    By dbassett74 in forum 1.x Help
    Replies: 0
    Last Post: May 26, 2009, 4:25 PM

Posting Permissions