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

onclose and onbefore close are firing onopen???

2 Answers 76 Views
Window
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 25 Jun 2012, 07:51 PM
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 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 26 Jun 2012, 10:37 AM
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.
0
John
Top achievements
Rank 1
answered on 26 Jun 2012, 12:13 PM
Thanks Martin. Everything's working as it should now.
Tags
Window
Asked by
John
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
John
Top achievements
Rank 1
Share this question
or