This is a migrated thread and some comments may be shown as answers.

Custom Properties for Dynamically created RadWindow from Code Behind

1 Answer 252 Views
Window
This is a migrated thread and some comments may be shown as answers.
Sabrina Schubert
Top achievements
Rank 1
Sabrina Schubert asked on 02 Jun 2010, 01:32 PM

Hi,

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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml" > 
<head runat="server">  
    <title></title>  
    <script type="text/javascript">  
        function WindowCreatedAndShowed(sender, args) {  
            if (sender.isMinimized == "True") {  
                sender.hide();  
            }  
        }  
    </script> 
</head> 
<body> 
    <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">          
    </telerik:RadWindowManager> 
    </form> 
</body> 
</html> 
 

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)  
            {  
                try 
                {  
                    //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);  
                            }  
                            else 
                            {  
                                AddWidgetsForEachMainTab(objEntityMainTab, false);  
                            }  
                        }  
                    }  
                    else 
                    {  
                        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  
                DBRadWindowManager.Windows.Add(objTabWindow);  
            }  
        }  
    }  
 
    //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;}  
    }  
}  
 

1 Answer, 1 is accepted

Sort by
0
Petio Petkov
Telerik team
answered on 04 Jun 2010, 04:30 PM
Hello Sabrina,

The code below is a simple example, which illustrates how to pass and use values via RadWindow's attributes on the client.
ASPX:
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head id="Head1" runat="server">
    <title></title>
     
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
     <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");
             alert(atributeValue);
         }      
    </script>    
    <div>
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server" OnClientPageLoad="WindowCreatedAndShowed">
        </telerik:RadWindowManager>
          
    </div>
    </form>
</body>
Codebehind:
protected void Page_Load(object sender, EventArgs e)
 {
     RadWindow win = new RadWindow();
     win.ID = "MyWindow";
     win.Attributes["MyAttribute"] = "SomeAttribute";
     win.VisibleOnPageLoad = true;
     win.NavigateUrl = "http://www.google.com";
     RadWindowManager1.Windows.Add(win);
 }
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.
Tags
Window
Asked by
Sabrina Schubert
Top achievements
Rank 1
Answers by
Petio Petkov
Telerik team
Share this question
or