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

[Solved] Cant use RadWindowManager from load event of page

2 Answers 181 Views
Window
This is a migrated thread and some comments may be shown as answers.
milan masat
Top achievements
Rank 1
milan masat asked on 12 Feb 2010, 10:58 AM
Hi, your RadWindow component is really smart and usefull thing, but i have at moment following problem:
I try to call open or radopen function from onload event of browser window to dynamically create some radwindow objects on the page.
But in every case is result of "$find("RadWindowManage1")" null. Why ? If i try to get RadWindowManager by
 "$get("RadWindowManage1")", object is indeed present but still not ready for use of their JS functions.
It seems the needed javascript funcionality is not yet present at this moment.
Could you give me some advise how to use that object during loading of the page ?
See attached aspx.
Thaks for your answer.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ReportCanvas.aspx.cs" Inherits="VS3.DashboardReports.ReportCanvas" %>

<%@ 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">

<html xmlns="http://www.w3.org/1999/xhtml" >

<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">

    <script type="text/javascript">
      
        function onRequestStart(sender, args)
        {
        }
       
        function onResponseEnd(sender, args)
        {
        }  
      
    </script>
   
</telerik:RadCodeBlock>

<head runat="server">
    <title>Report Canvas</title>   
    <style type="text/css">
        BODY
        {
            margin: 0px 0px 0px 0px;
            padding: 0px 0px 0px 0px;
        }
    </style>
</head>

<body>
   
    <form id="form1" runat="server">

        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
        </telerik:RadScriptManager> 

        <div id="divCanvasHolder" runat="server" class="CanvasHolder">       
        </div>
       
        <telerik:RadWindowManager ID="RadWindowManager1" runat="server"
                                  PreserveClientState="True" KeepInScreenBounds="True" />
       
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server" OnAjaxRequest="RadAjaxManager1_AjaxRequest">
            <ClientEvents OnRequestStart="onRequestStart" OnResponseEnd="onResponseEnd" />
        </telerik:RadAjaxManager>
   
    </form>
      
</body>

<telerik:RadCodeBlock ID="RadCodeBlock2" runat="server">

    <script type="text/javascript">

        var textPanelSetupUrl = "TextPanelSetup.aspx?PanelId=";
        var imagePanelSetupUrl = "ImagePanelSetup.aspx?PanelId=";
        var queryPanelSetupUrl = "QueryPanelSetup.aspx?PanelId=";
       
        function ApplyCanvasSettings(width, height, background)
        {
            var divCanvasHolder = document.getElementById("divCanvasHolder");
            divCanvasHolder.style.width = width + "px";
            divCanvasHolder.style.height = height + "px";
            divCanvasHolder.style.backgroundColor = background;
        }
                                    
        function OpenPanel(title, id, leftPos, topPos, width, height, isNew, type)
        {
            debugger
            var oWnd = GetWindowManager().open(null, "Panel" + id);

            var titleTable = oWnd._titlebarElement.firstChild.firstChild;
            titleTable.removeChild(titleTable.firstChild);

            oWnd.setSize(width, height);
            oWnd.panelId = id;
           
            if (isNew)
                oWnd.center();
            else
                oWnd.moveTo(leftPos, topPos);
           
            oWnd.set_visibleStatusbar(false);
            oWnd.set_restrictionZoneID("<%=divCanvasHolder.ClientID%>");
            oWnd.set_destroyOnClose(true);
            oWnd.set_behaviors(Telerik.Web.UI.WindowBehaviors.Move +
                               Telerik.Web.UI.WindowBehaviors.Close +
                               Telerik.Web.UI.WindowBehaviors.Resize);
                                         
            oWnd.add_close(onPanelClose);
            oWnd.add_resize(onPanelResize);
            oWnd.setUrl(GetPanelSetupUrl(type) + id);           
            oWnd.set_title(title);           
        }
               
        function GetPanelSetupUrl(type)
        {
            switch (type)
            {
                case 0:
                    return textPanelSetupUrl;
                case 1:
                    return imagePanelSetupUrl;
                case 2:
                    return queryPanelSetupUrl;
            }
        }
                                   
        function onPanelClose(sender, eventArgs)
        {       
            var args = "Close||" + sender.panelId;
            var ajaxManager = GetAjaxManager();
            ajaxManager.ajaxRequest(args);
        }
      
        function onPanelResize(sender, eventArgs)
        {
            var contentFrame = sender.GetContentFrame();
            contentFrame.contentWindow.onResize();
        }
      
        function GetPanels()
        {
            return GetWindowManager().get_windows();
        }

        function GetAjaxManager()
        {
            return $find("<%=RadAjaxManager1.ClientID%>");
        }

        function GetWindowManager()
        {
            return $find("<%=RadWindowManager1.ClientID%>");
        }
       
        window.onload = function()
        {
            debugger
            var wm = GetWindowManager();
           
        }      
              
    </script>

</telerik:RadCodeBlock>

</html>

2 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 12 Feb 2010, 12:28 PM
Hello milan,

In ASP.NET AJAX, all ASP.NET AJAX controls (including ours) are loaded not in window.onload, but on a later stage - Sys.Application.Init. You can verify that by examining the HTML dump of a page with ASP.NET AJAX controls on it.
That is the reason why your code is not working - when you try to access the RadWindowManager, it is still not rendered on the page. In your case I would suggest to use the ASP.NET AJAX native pageLoad() function instead of window.onload - if you have a ScriptManager on that page, this function will be automatically called when all ASP.NET AJAX controls are loaded.


Best wishes,
Georgi Tunev
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.
0
milan masat
Top achievements
Rank 1
answered on 12 Feb 2010, 12:48 PM
Georgi,
many thanks for your lesson in ASP.NET AJAX. Your suggestion is exactly what i need, it is working fine now.
Tags
Window
Asked by
milan masat
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
milan masat
Top achievements
Rank 1
Share this question
or