
In dispose, it has:
if(this._onResizeDelegate){
$removeHandler(window,"resize",this._onResizeDelegate);
this._onResizeDelegate=null;
}
This part of the code seems fine.
However, _initializeDimensions has:
if(navigator.userAgent.toLowerCase().indexOf("msie")!=-1){
this._onResizeDelegate=Function.createDelegate(this,this.onWindowResize);
setTimeout(function(){
$addHandler(window,"resize",_1._onResizeDelegate);
},0);
}else{
this._onResizeDelegate=Function.createDelegate(this,this.onWindowResize);
$addHandler(window,"resize",this._onResizeDelegate);
}
The problem is that the resize delegate is saved before the handler is actually added via a call to setTimeout. If the window's location changes before this setTimeout method runs, an exception is thrown because $removeHandler is called when $addHandler never was.
I believe the corrected code would be as follows:
if(navigator.userAgent.toLowerCase().indexOf("msie")!=-1){
setTimeout(function(){
this._onResizeDelegate=Function.createDelegate(this,this.onWindowResize);
$addHandler(window,"resize",_1._onResizeDelegate);
},0);
}else{
this._onResizeDelegate=Function.createDelegate(this,this.onWindowResize);
$addHandler(window,"resize",this._onResizeDelegate);
}
Simply move setting the resize delegate inside anonymous delegate executed by setTimeout. This way, if setTimeout never runs, the resize delegate is null and $removeHandler is never called.
If necessary, I can post an example of this error. It's easily reproduced via something like a client-side refresh/redirect.
Thanks for looking into this.
David
10 Answers, 1 is accepted
Thank you for contacting us.
We are not aware of such a problem - it seems there is something specific in your setup. Could you open a support ticket and send a sample runnable project that demonstrates the issue? Once we are able to reproduce the problem we will do our best to find the source of the problem.
Regards,
Plamen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center

Default.aspx:
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%
@ 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">
<
head runat="server">
<title>Test Page</title>
</
head>
<
body>
<form id="form1" runat="server">
<telerik:RadGrid ID="testGrid" runat="server">
<ClientSettings>
<Scrolling AllowScroll="true" />
</ClientSettings>
</telerik:RadGrid>
<asp:ScriptManager ID="scriptManager" runat="server" EnablePartialRendering="true" />
<script type="text/javascript">
function onLoad() {
Sys.Application.initialize();
reload();
}
function reload() {
if (window.location.href.indexOf('?redirected') == -1) {
window.location.replace(window.location.href +
'?redirected=true');
}
}
window.onload = onLoad;
</script>
</form>
</
body>
</
html>
Default.aspx.cs:
using
System;
public
partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
TestDataItem[] dataSource = new TestDataItem[] { new TestDataItem("Test 1A", "Test 1B"), new TestDataItem(
"Test 2A", "Test 2B") };
testGrid.DataSource = dataSource;
testGrid.DataBind();
}
private class TestDataItem
{
private string _item1;
public string Item1
{
get { return _item1; }
set { _item1 = value; }
}
private string _item2;
public string Item2
{
get { return _item2; }
set { _item2 = value; }
}
public TestDataItem(string item1, string item2)
{
_item1 = item1;
_item2 = item2;
}
}
}
David

The following code example demonstrates how to achieve your goal:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> |
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml"> |
<head runat="server"> |
<title>Untitled Page</title> |
</head> |
<body> |
<form id="form1" runat="server"> |
<asp:ScriptManager ID="ScriptManager1" runat="server" /> |
<div> |
<telerik:RadGrid ID="testGrid" runat="server"> |
<ClientSettings> |
<Scrolling AllowScroll="true" /> |
</ClientSettings> |
</telerik:RadGrid> |
<script type="text/javascript"> |
function pageLoad() |
{ |
setTimeout("reload()", 0); |
} |
function reload() |
{ |
if (window.location.href.indexOf('?redirected') == -1) |
{ |
window.location.replace(window.location.href + '?redirected=true'); |
} |
} |
</script> |
</div> |
</form> |
</body> |
</html> |
load event - Raised after all scripts have been loaded and all objects in the application that are created by using $create are initialized. The load event is raised for all postbacks to the server, which includes asynchronous postbacks.
If you are a page developer, you can create a function that has the name pageLoad, which automatically provides a handler for the load event. The pageLoad handler is called after any handlers that have been added to the load event by the add_load method.
The load event takes an eventargs parameter, which is an Sys.ApplicationLoadEventArgs object. You can use the event arguments to determine whether the page is being refreshed as a result of a partial-page update and what components were created since the previous load event was raised.
Regards...
<John:Peel />

Thanks for the assistance, but unfortunately that's not what I'm trying to do. The problem is a bug in the Grid that only appears if the user leaves the page between grid initialization and the setTimeout call to register the handler. When that happens, dispose tries to remove a handler that was never added. My sample is an attempt to reproduce this bug programatically.
David


I have found a forum link from the asp net forum which discusses a similar issue:
http://forums.asp.net/p/1055781/1705462.aspx
Hope this helps...
<John:Peel />

It is always specifically to do with removing _onResizeDelegate from the window.resize event.
The original poster pinpointed the error in the code - see below:
if(navigator.userAgent.toLowerCase().indexOf("msie")!=-1){ |
this._onResizeDelegate=Function.createDelegate(this,this.onWindowResize); |
setTimeout(function(){ |
$addHandler(window,"resize",_1._onResizeDelegate); |
},0); |
_onResizeDelegate is created, but the attachment is done inside a setTimeout call, presumably to make sure all the DOM content is loaded before running. But dispose runs:
if(this._onResizeDelegate){ |
$removeHandler(window,"resize",this._onResizeDelegate); |
this._onResizeDelegate=null; |
} |
So there will always be a possibility that _onResizeDelegate will exist here, but not be attached.(if another piece of script redirects the page say before the handler can be attached).
This would cause the observed error.
The original poster even suggested a fix - move the creation of the delegate inside the setTimeout function.
Can this be fixed? It's causing quite serious errors in our site.
Thanks,
Stephen
Could you open a support ticket and send a sample runnable project that demonstrates the issue? Once we are able to reproduce the problem we will do our best to find the source of the problem.
Greetings,
Plamen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.

"The source of the problem" seems quite apparent though, there's a fairly obvious race condition here, that means if dispose runs before the setTimeout($addHandler) code, you'll get the error.
Will try to upload a project.
Thanks,
Stephen
We will be expecting your example once you are ready with it.
Best regards,
Stephen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.