onclose and onbefore close are firing onopen???

3 posts, 0 answers
  1. John
    John avatar
    5 posts
    Member since:
    Jun 2012

    Posted 25 Jun 2012 Link to this post

    Ok I'm kinda new to the Telerik tools so hope this doesn't sound too strange...

    I created a user control with the RadWindowManager and a jscript function to open the window as below:

    <%@ Control Language="VB" AutoEventWireup="false" CodeFile="RadWindowManager.ascx.vb" Inherits="Controls_RadWindowManager" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <telerik:RadWindowManager 
        runat="server" 
        RestrictionZoneID="offsetElement" 
        EnableShadow="true" 
        ShowOnTopWhenMaximized="false" 
        VisibleStatusbar="false"
        Behaviors="Close, Move, Resize, Maximize" 
        Opacity="99" 
        Height="400" 
        Width="400" >
    </telerik:RadWindowManager>
     
    <script type="text/javascript">
        function OpenRadWindow(urltitlewidthheightmodalonBeforeCloseEventonCloseEvent) {
            if (url == null) { url = "" }
            if (title == null) { title = "" }
            if (width == null) { width = 400 }
            if (height == null) { height = 400 }
            if (modal == null) { modal = true }
     
            var wnd = window.radopen(urlnull);
            wnd.SetTitle(title);
            wnd.setSize(widthheight);
            wnd.set_modal(modal);
            if (onBeforeCloseEvent != null) {
                wnd.add_beforeClose(onBeforeCloseEvent);
            }
            if (onCloseEvent != null) {
                wnd.add_onClose(onCloseEvent);
            }
     
            return false;
        }
    </script>

    The idea was to not have to declare it all over the place as we have many popups in our system and some require different variables than others.

    Anyways Part 2:

    In one of my pages I have a popup that requires some inputs and such and needs to refresh the main page when it closes.

    <%@ Register Src="~/Controls/RadWindowManager.ascx" TagName="RadWindowManager" TagPrefix="uc3" %>
    
    <uc3:RadWindowManager ID="RadWindowManager" runat="server" />
    
    function OpenAddProduct() {  
                var url = <%= """" & ResolveUrl("~/Levels/Products.Aspx?Popup=1") & """" %>;
                OpenRadWindow(url"Manage Products"765500truenullalert("This is supposed to be a close event..."));
            }

    Obviously what I am expecting is when the window is closed an alert to popup with that message, however what I am getting is that as soon as the window opens it is firing the OnClose event the same goes for the OnBeforeClose as well.

    Am I just doing something wrong here declaring the window or is there more to it???
  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    5706 posts

    Posted 26 Jun 2012 Link to this post

    Hi John,

    You need to feed a variable of type function to the methods of the RadWindow that handle its events. In your current code the object that is the onCloseEvent variable is actually a call to the alert, not to a function, so once it gets accessed it gets executed.

    Another problem is that the add_close() method is misspelled in your case to add_onClose. The list with the available methods is available in this help article.

    That being said, the following syntax should get things going:
    function OpenAddProduct()
    {
        function someFunction() { alert("This is supposed to be a close event..."); }
        OpenRadWindow(url, "Manage Products", 765, 500, true, null, someFunction);
    }

    function OpenRadWindow(url, title, width, height, modal, onBeforeCloseEvent, onCloseEvent)
    {
        if (url == null) { url = "" }
        if (title == null) { title = "" }
        if (width == null) { width = 400 }
        if (height == null) { height = 400 }
        if (modal == null) { modal = true }
     
        var wnd = window.radopen(url, null);
        wnd.SetTitle(title);
        wnd.setSize(width, height);
        wnd.set_modal(modal);
        if (onBeforeCloseEvent != null)
        {
            wnd.add_beforeClose(onBeforeCloseEvent);
        }
        if (onCloseEvent != null)
        {
            wnd.add_close(onCloseEvent);
        }
     
        return false;
    }


    Kind regards,
    Marin Bratanov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. John
    John avatar
    5 posts
    Member since:
    Jun 2012

    Posted 26 Jun 2012 Link to this post

    Thanks Martin. Everything's working as it should now.
Back to Top