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

Using add_resize to subscribe to client-side window resize events?

17 Answers 384 Views
Window
This is a migrated thread and some comments may be shown as answers.
MdB
Top achievements
Rank 1
MdB asked on 29 Jan 2008, 02:58 PM
Hello,

My ASP.NET 3.5 app uses a Prometheus Q3 RadWindow containing a single editor control. I would like the editor control to fill the entire RadWindow, even if the user resizes the window (in addition, I'd like to impose a minimum size on the window, but that's another issue). I'm using the following client-side code to achieve this:

<head>
    <script type="text/javascript">
        function getRadWindow() {
            var oWnd=null;
            if (window.radWindow) oWnd=window.radWindow;
            else if (window.frameElement.radWindow) oWnd=window.frameElement.radWindow;
            return oWnd;
        }
       
        function ResizeEditor() {
            var editor=$find("<%=Editor.ClientID%>");
            editor.setSize(getRadWindow().get_Width()-45,getRadWindow().get_Height()-75);
        }
       
        function pageLoad() {
            ResizeEditor();   
            getRadWindow().add_resize(ResizeEditor); //doesn't work!
        }
    </script>
</head>


The initial ResizeEditor() call in pageLoad() works just fine, and the editor is resized to fill the RadWindow just after it loads (the visible resizing isn't as pretty as I'd like, but at least it works...). However, the add_resize causes a JavaScript error: a stack overflow message box in IE7 and "too much recursion" somewhere in ScriptResource.axd when using Firefox.

This happens even when I use a dummy function as the add_resize argument, and also when I use add_close instead of add_resize.

What is the correct way to use add_resize in this scenario? And/or is there a better way to achieve the desired functionality?

Thanks!
Michiel de Bruijn

17 Answers, 1 is accepted

Sort by
0
Georgi Tunev
Telerik team
answered on 31 Jan 2008, 02:00 PM
Hello MdB,

The "stack overflow" problem is due to the debug code that is executed on the client when compilation debug is set to true. Unfortunately this is an ASP.NET AJAX issue and we cannot do much about it on our side. The only workaround at this point is to set <compilation debug="false"> in the web.config file of your application.

By the way, I checked your code and I see that you take only the initial size of the RadWindow here:
editor.setSize(getRadWindow().get_Width()-45,getRadWindow().get_Height()-75);

I would recommend changing get_Width() and get_Height() methods with getWindowBounds().height / getWindowBounds().width ones.





Sincerely yours,
Georgi Tunev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Tatiana Bogdanova
Top achievements
Rank 1
answered on 17 Mar 2008, 08:15 PM
Hi Michiel!
You can implement OnClientResize event handler in parent window and call ResizeEditor function from it:

sender.get_ContentFrame().contentWindow.ResizeEditor();

Thanks,
Tatiana
0
Courouble Damien
Top achievements
Rank 1
answered on 15 Sep 2009, 04:44 PM
Hi everybody,

I've got the same problem when i try to add an onclientclose event to GetRadWindow with GetRadWindow.add_close(myfunction)

What can i do to call "myfunction" when the user is closing the window ?

Thanks in advance,

Damien
0
Fiko
Telerik team
answered on 18 Sep 2009, 09:47 AM
Hello Damien,

The approach that you used is the right one. Could you please modify the compilation section in the web.config file, as mentioned earlier in this thread?
<compilation debug="false"

After that you will not experience the same error.

All the best,
Fiko
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Courouble Damien
Top achievements
Rank 1
answered on 23 Sep 2009, 02:51 PM
Hi,

I'm sorry to answer only now, I was sick to be honest, so I tried (again) with setting debug to false, but that doesn't change anything !

Is there another solution ?

Thanks

Damien

0
Courouble Damien
Top achievements
Rank 1
answered on 23 Sep 2009, 03:30 PM
Well,

I should give you some apologies that's work !
But it's an annoying solution, the problem will be fixed in the new version ? is it considered as bug ?

thanks

Damien

0
Georgi Tunev
Telerik team
answered on 24 Sep 2009, 08:34 AM
Hello Damien,

As noted in this thread, the stack overflow error that arises from this is due to a problem in the MS AJAX framework and we cannot fix it on our side.

The good news however is that we managed to find a workaround. The idea is to ensure that the function added to some object with add_close is in the context of the page where the object is.
e.g. in the case with RadWindow:

var oWnd = GetRadWindow(); 
var browserWin = oWnd.BrowserWindow; 
var fn = new browserWin.Function("sender","args""alert(sender + ' was closed');"); 
oWnd.add_close(fn); 

I hope this helps. Same holds true for the add/remove_pageLoad
()/resize() functions. That is why we would recommend to consider moving these functions in the parent page (where the RadWindow objects are) and to call them from within the content page when needed.
More information on the subject is available here.


Kind regards,
Georgi Tunev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Courouble Damien
Top achievements
Rank 1
answered on 24 Sep 2009, 09:55 AM
Hi Georgi Tune,

The approach you told me is the right one, I don't have any errors of javascript on each browser, and i'm in debug mode :)
That's nice to be help as we are with telerik forum !

Thanks again,

Damien
0
Courouble Damien
Top achievements
Rank 1
answered on 05 Oct 2009, 03:00 PM
Hi again,

Today I need to modify this code :

function SetRefreshGridOnClose() {
    var oWnd = GetRadWindow();
    var browserWin = oWnd.BrowserWindow;
    var fn = new browserWin.Function("sender", "args", "alert('hello')");
    oWnd.add_close(fn);
}

for calling a new function as third args of browserWin.Function
you know :  new browserWin.Function("sender","args", "myfunction")

I've definied "myfunction" as

function myfunction(){
alert("my function is called");
}

but nothing ever happen ..

what should I do to call "myfunction" in the add_close event of my radwindow ?

thanks

Damien



0
Georgi Tunev
Telerik team
answered on 07 Oct 2009, 12:00 PM
Hi Damien,

The third argument is the code that you wish to be executed, so you should call the second function like this:

new browserWin.Function("sender","args", "myfunction();")


Best wishes,
Georgi Tunev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Courouble Damien
Top achievements
Rank 1
answered on 08 Oct 2009, 08:34 AM
I'm sorry, but if I do that :

function AddCloseGroupAdd(pButton) {
    var oWnd = GetRadWindow();
    var browserWin = oWnd.BrowserWindow;
    var fn = new browserWin.Function("sender", "args", "myfunction();");
    oWnd.add_close(fn);
}

function myfunction() {
    alert("hello");
}

I always got a javascript error ( "myfunction is not defined")

Am I doing something wrong ?
0
Shinu
Top achievements
Rank 2
answered on 08 Oct 2009, 09:25 AM
Hi,

Have you added the myfunction() in browser window? I tried adding the function in browser window and found it is working fine.

-Shinu.
0
Georgi Tunev
Telerik team
answered on 08 Oct 2009, 12:54 PM
Hi guys,

Damine, as Shinu said, myfunction() should be declared on the parent page, e.g. the page where you create and execute the new function. I am not quite sure what exactly is your real scenario and what logic you wish to implement, but I suggest to open a support ticket and to send me a small sample that illustrates this. I will check it and will do my best to provide you with the most appropriate solution.


Sincerely yours,
Georgi Tunev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Vaughan Reed
Top achievements
Rank 1
answered on 07 Feb 2010, 09:41 PM
I have the same issue.

My problem is that I am calling a dialog from a dialog so BrowserWindow is of no use. I need to be able to call the close event declared in the calling window.

How do I get the calling dialog (I am not using a window manager in the calling dialog) from my child dialog and how do I add the close event?
0
Georgi Tunev
Telerik team
answered on 09 Feb 2010, 01:09 PM
Hello Vaughan,

This thread is getting quite long and I am not quite sure which issue you are referring to. Please open a support ticket and send us a small sample project that shows your exact setup along with detailed description of the desired behavior - we will check it and do our best to help.


Kind regards,
Georgi Tunev
the Telerik team

Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Follow the status of features or bugs in PITS and vote for them to affect their priority.
0
Ron
Top achievements
Rank 1
Veteran
answered on 24 Jan 2011, 02:12 PM
I am dealing with the exact same problem. Opening a modal radwindow (2) from another modal radwindow (1) and having a client close event handler on the first radwindow (1). What I did was define a delegate function in the page that includes the window definition and windowmanager (in other words, the window opening the first modal radwindow (1)).

function delegate(thatMethod) {
    return function (sender, args) {
        return thatMethod.call(this, sender, args);
    }
}

The javascript function opening the second modal radwindow looks something like this. Basically the onclientclose event handler defined in the first radwindow's context is wrapped by the delegate one which is in the page's context that contains the window manager.

function OpenWindow(url, windowName, onclientclose) {
    var oMgr = GetRadWindow().get_windowManager();
    var oWnd = oMgr.open(url, windowName);
    if (onclientclose) oWnd.add_close(oWnd.BrowserWindow.delegate(onclientclose));
    oWnd.center();
    return oWnd;
}

This works ok and should resolve your problem.

The only problem I am facing now is how to remove the delegate from the radwindow's eventhandler list. Since the window isn't destroyed after usage, I have to unregister my onclose event handler. So I would like to call oWnd.remove_close(onclientclose) from the eventhandler itself. So if I pass a reference to the following function OnSelectReference, I would like to unregister it by calling wnd.remove_close(OnSelectReference). Unfortunately it's not the OnSelectReference function that is registered but the delegate. How to unregister my delegate now?

    function OnSelectReference(wnd, args) {
           wnd.remove_close(OnSelectReference); // this won't work, since the delegate is registered
           // function content
           ...
    }
0
Ron
Top achievements
Rank 1
Veteran
answered on 24 Jan 2011, 02:36 PM
I seem to be having it working now. A little funky but it works.

Set 'this' for the wrapped method to a reference to the wrapping delegate.
function delegate(thatMethod) {
    var f = function (sender, args) {
        return thatMethod.call(f, sender, args);
    }
    return f;
}

Unregister from the event handler.
function OnSelectReference(wnd, args) {
   wnd.remove_close(this); // 'this' will be a reference to the delegate
   // body content
   ...
}

Hope this helps
Tags
Window
Asked by
MdB
Top achievements
Rank 1
Answers by
Georgi Tunev
Telerik team
Tatiana Bogdanova
Top achievements
Rank 1
Courouble Damien
Top achievements
Rank 1
Fiko
Telerik team
Shinu
Top achievements
Rank 2
Vaughan Reed
Top achievements
Rank 1
Ron
Top achievements
Rank 1
Veteran
Share this question
or