Feb 19, 2010, 12:43 PM
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
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.