Custom Properties for Dynamically created RadWindow from Code Behind

2 posts, 0 answers
  1. Sabrina Schubert
    Sabrina Schubert avatar
    5 posts
    Member since:
    May 2010

    Posted 02 Jun 2010 Link to this post


    I am creating windows dynamically based on the settings I retrieve from database. Need to add some custom properties to the RadWindows so that I can use them while rendering to make decissions, like whether to show it in the minimized mode after its visible(because I've many rad windows popping up on the screen). Attributes which will drive the minimum width and height of the windows, which I'll use in the resize event of the RadWindows.

    I've a code sample here, kindly help me understand how I can do this.

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %> 
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> 
    <html xmlns="" > 
    <head runat="server">  
        <script type="text/javascript">  
            function WindowCreatedAndShowed(sender, args) {  
                if (sender.isMinimized == "True") {  
        <form id="form1" runat="server">      
        <telerik:RadWindowManager ShowOnTopWhenMaximized="false" Width="100%" Height="100%" 
            OnClientActivate="OnClientActivate" OnClientClose="OnClientClose" Behaviors="Close,Maximize,Minimize,Move,Reload,Resize" 
            OnClientCommand="OnClientCommand" ID="DBRadWindowManager" RestrictionZoneID="RestrictionZone" 
            runat="server" Skin="Telerik" OnClientPageLoad="WindowCreatedAndShowed" OnClientResize="OnClientResize">          

    Code Behind:

    using System;  
    using System.Collections.Generic;  
    using System.Linq;  
    using System.Web;  
    using System.Web.UI;  
    using System.Web.UI.WebControls;  
    using Telerik.Web.UI;  
    namespace WebApplication2  
        public partial class _Default : System.Web.UI.Page  
            protected void Page_Load(object sender, EventArgs e)  
                if (!Page.IsPostBack)  
                        //Get the currently logged in user's Tab-Widgets collection  
                        List<Tab> objTabsCollection = GetUserTabsWidgetsCollection(); //Gets the data  
                        if (objTabsCollection != null && objTabsCollection.Count > 0)  
                            int tabCounter = 1;  
                            //Loop through all the Tabs the user is authorized to view, add the Tabs to the MainTabStrip,  
                            //Add PageView to each of the Main tab, Add TabStrip to each of the PageView (Widget level Tabstrip),  
                            //Add Widgets to the WindowManager collection to add the association with the widget tabstrip  
                            foreach (Tab objEntityMainTab in objTabsCollection)  
                                //If it is the first tab, then make widgets visible, set the tab to the selected tab and  
                                //set the PageView of the tab to selected.  
                                if (tabCounter++ == 1)  
                                    //Add widgets associated with the Main tab  
                                    AddWidgetsForEachMainTab(objEntityMainTab, true);  
                                    AddWidgetsForEachMainTab(objEntityMainTab, false);  
                            Server.Transfer(string.Format("{0}Item=You are not authorized to view any pages in this application.", UnauthorizedPagePath));  
                    catch (Exception ex)  
                        //Exception Handling  
            /// <summary>  
            /// Adds the Widgets associated with given Main tab  
            /// </summary>  
            /// <param name="objUIMainTab">Main tab for which the associated widgets need to be added</param>  
            /// <param name="objEntityMainTab">Entity Tab object that consists of the Widgets information for the Main tab</param>  
            /// <param name="isWidgetVisible">Tells if the widgets needs to be visible on initial page load</param>  
            private void AddWidgetsForEachMainTab(Tab objEntityMainTab, bool isWidgetVisible)  
                short tabIndex = 1;  
                //Create Tab & associated RadWindows for each of the sub tab in the Main tab  
                foreach (Widget objWidget in objEntityMainTab.Widgets)  
                    //Create RadWindow for the Tab  
                    RadWindow objTabWindow = new RadWindow();  
                    objTabWindow.ID = objWidget.Widget_Name.ToUpper() + "_WINDOW";  
                    objTabWindow.VisibleOnPageLoad = true;  
                    objTabWindow.TabIndex = tabIndex++;  
                    objTabWindow.BorderStyle = BorderStyle.None;  
                    objTabWindow.Behaviors = WindowBehaviors.Default;  
                    objTabWindow.Height = Unit.Pixel(objWidget.Initial_Height);  
                    objTabWindow.InitialBehaviors = WindowBehaviors.None;  
                    objTabWindow.Left = Unit.Pixel(objWidget.Widget_Left);  
                    objTabWindow.ReloadOnShow = true;  
                    objTabWindow.Skin = "Telerik";  
                    objTabWindow.Title = objWidget.Widget_Name;  
                    objTabWindow.Top = Unit.Pixel(objWidget.Widget_Top);  
                    objTabWindow.Width = Unit.Pixel(objWidget.Initial_Width);  
                    objTabWindow.IconUrl = "~/images/bg-header-widget.gif";  
                    objTabWindow.NavigateUrl = objWidget.Widget_NavigateURL;  
                    objTabWindow.Behaviors = WindowBehaviors.Minimize | WindowBehaviors.Maximize | WindowBehaviors.Move | WindowBehaviors.Reload | WindowBehaviors.Resize;  
                    objTabWindow.KeepInScreenBounds = true;  
                    objTabWindow.VisibleOnPageLoad = isWidgetVisible;  
                    objTabWindow.Visible = true;  
                    objTabWindow.VisibleStatusbar = false;  
                    //Attributes for the Minimum Height and Width for each of the widgets   
                    //along with the value if the widgets needs to be in minimized state while loading  
                    objTabWindow.Attributes.Add("isMinimized", objWidget.IsMinimized ? Boolean.FalseString : Boolean.TrueString);  
                    objTabWindow.Attributes.Add("MinimunHeight", Convert.ToString(objWidget.Minimum_Height));  
                    objTabWindow.Attributes.Add("MinimunWidth", Convert.ToString(objWidget.Minimum_Width));  
                    //Add the newly created RadWindow to the RadWindowManager  
        //Tab & Widget classes definition  
        public class Tab  
            public int Tab_Id { getset; }  
            public string TabName { getset; }  
            public string CreateID { getset; }          
            public List<Widget> Widgets { getset; }  
        public class Widget  
            public int Widget_Id {get;set;}  
            public string Widget_Name {get;set;}  
            public string Widget_NavigateURL {get;set;}  
            public bool IsMinimized {get;set;}  
            public int Widget_Left {get;set;}  
            public int Widget_Top {get;set;}  
            public int Initial_Height {get;set;}  
            public int Initial_Width {get;set;}  
            public int Minimum_Width {get;set;}  
            public int Minimum_Height {get;set;}  
  2. Petio Petkov
    Petio Petkov avatar
    825 posts

    Posted 04 Jun 2010 Link to this post

    Hello Sabrina,

    The code below is a simple example, which illustrates how to pass and use values via RadWindow's attributes on the client.
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
    <head id="Head1" runat="server">
        <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
         <script type="text/javascript">
             function WindowCreatedAndShowed(oWin, args)
                 //Get RadWindow's element
                 var oWinElement = oWin.get_element();
                 //Get attribute's value
                 var atributeValue = oWinElement.getAttribute("myAttribute");
            <telerik:RadWindowManager ID="RadWindowManager1" runat="server" OnClientPageLoad="WindowCreatedAndShowed">
    protected void Page_Load(object sender, EventArgs e)
         RadWindow win = new RadWindow();
         win.ID = "MyWindow";
         win.Attributes["MyAttribute"] = "SomeAttribute";
         win.VisibleOnPageLoad = true;
         win.NavigateUrl = "";
    Let us know if you have any other questions.

    All the best,
    Petio Petkov
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Back to Top