Adding DesktopWindow dynamically to the Page and use it by Desktop.Module controls

  1. #1

    Adding DesktopWindow dynamically to the Page and use it by Desktop.Module controls

    I was wondering if there is a way to add the modules, short cuts and Desktop window dynamically from code behind.

    The following example demonstrates how to do it, but if you set the windowId of the shortcut then the following exception will raise at run time.

    The DesktopWindow with the ID of 'window_0' was not found



    I have used this piece of code in the PageLoad event handler of Site.Master

    if (!Ext.IsAjaxRequest)
                {
                    Coolite.Ext.Web.DesktopModule dm;
                    Coolite.Ext.Web.DesktopShortcut ds;
                    for (int i = 0; i < 20; i++)
                    {
                        dm = new DesktopModule();
                        dm.ModuleID = string.Format("Module_{0}", i);
                        dm.Launcher.Text = string.Format("Module {0}", i);
                        dm.Launcher.Icon = Icon.Cog;
    
    
                        if (i % 3 == 0)
                        {
                            DesktopWindow dw = new DesktopWindow();
                            dw.ID = string.Format("window_{0}", i);
                            dw.CenterOnLoad = true;
                            dw.Title = dm.Launcher.Text;
                            dw.Icon = dm.Launcher.Icon;
                            dw.Width = 300;
                            dw.Height = 400;
                            this.form1.Controls.Add(dw);
    
                            // The following line causes a runtime exception
                            //dm.WindowID = dw.ID;
    
                            ds = new DesktopShortcut();
                            ds.Text = dm.Launcher.Text;
                            ds.IconCls = "shortcut-icon icon-user48";
                            ds.ModuleID = dm.ModuleID;
                            ds.ShortcutID = string.Format("shortcut_{0}", i);
    
                            ctrlDesktop.Shortcuts.Add(ds);
                        }
                        else
                        {
                            dm.Launcher.Listeners.Click.Handler = string.Format("createDynamicWindow(#{0}{1}{2}, '{3}');", "{", ctrlDesktop.ClientID, "}", "http://www.google.co.uk");
                        }
                        ctrlDesktop.Modules.Add(dm);
    Site.Master:
    <body>
        <form id="form1" runat="server">
            <ext:ScriptManager ID="ScriptManager1" runat="server" ScriptMode="Debug" Theme="Default">
                <Listeners>
                </Listeners>
            </ext:ScriptManager>
            
            <ext:Desktop ID="ctrlDesktop" runat="server" BackgroundColor="Black" ShortcutTextColor="White" Wallpaper="content/desktop.jpg">
                <StartButton Text="Start" IconCls="start-button" />
                <Body />
                <Modules />
                <Shortcuts />
                <StartMenu />
            </ext:Desktop>
        </form>
    </body>
    regards.
  2. #2

    Adding DesktopWindow dynamically

    Hi gido,

    First you should add DesktopWindow. Next DesktopModule and DesktopShortcut as you can see on example below:

                    DesktopWindow dw = new DesktopWindow(); 
                    dw.ID = "window_1";
                    dw.Title = "window_1";
                    dw.Icon = Icon.Cog; 
                    dw.Width = 300; 
                    dw.Height = 400;
                    this.form1.Controls.Add(dw);
    
                    DesktopModule dm = new DesktopModule();
                    dm.ModuleID = "dm1";
                    dm.WindowID = "window_1";
                    dm.AutoRun = false;
                    dm.Launcher.ID = "ln1";
                    dm.Launcher.Text = "window_1";
                    dm.Launcher.Icon = Icon.Cog;
                    MyDesktop.Modules.Add(dm);
    
                    DesktopShortcut sht = new DesktopShortcut();
                    sht.ModuleID = "dm1";
                    sht.Text = "window_1";
                    sht.IconCls = "shortcut-icon icon-user48";
                    MyDesktop.Shortcuts.Add(sht);
    Regards.
    Last edited by piterson; Aug 17, 2010 at 10:12 PM.

Similar Threads

  1. Dynamically adding Controls to WebUserControl
    By bright in forum 1.x Help
    Replies: 8
    Last Post: Apr 27, 2012, 6:34 PM
  2. Replies: 2
    Last Post: Dec 15, 2011, 11:58 AM
  3. Replies: 2
    Last Post: Nov 04, 2009, 3:36 PM
  4. Desktop Module JS error
    By fenix2222 in forum Bugs
    Replies: 1
    Last Post: Mar 29, 2009, 2:21 PM
  5. [CLOSED] Dynamically adding controls to a tav
    By riccardosarti in forum 1.x Help
    Replies: 3
    Last Post: Sep 24, 2008, 9:49 AM

Posting Permissions