I have created a very small example..
It shows stack overflow at line 0..
There are two pages which are main.aspx and inner.aspx.
There is a button in inner.aspx.
When you click the button, a javascript object will be created and pass to main.aspx.
The problem is inside main.aspx. There is a method "testOpen1" which validates type of argument...
any idea?
<script type="text/javascript">
function testOpen1(arg1)
{ var typeResult1 = JasonSoft.JWindow.isInstanceOfType(arg1); //here is the problem...
alert(typeResult1);
hello. ah, a cool problem :) my version of the problem: when you register the types in 2 different windows you get 2 different types (even though their "signature" is identical). The problem is on this line (isInstanceOfType): var instanceType = Object.getType(instance);
return !!(instanceType === this) || (instanceType.inheritsFrom && instanceType.inheritsFrom(this)) || (instanceType.implementsInterface && instanceType.implementsInterface(this)); calling the instanceType will return the constructor of the class. well, if
you define everything on the same window, then you'll get a reference to the same function and everything should be ok. however, when you add iframes, you're getting new windows and this means that each window gets a copy of the type and that you have 2 different
methods/types and that's why you're getting the exception (btw, the exception is thrown from within the inherits from method called at the end of isInstanceOfType). The only workaround i see is defining the objects at the top window, but i'm not sure if this
is a viable option. another option is to use a simple js object, though you'll loose the benefits of OO programming introduced by the asp.net ajax platform.
--
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu
Right, this can't work, ever. Two different windows have separate copies of the type system. Except for built-in types, you can't reliably exchange objects between windows. The usual workaround is to use JSON structures instead.
Bertrand
----
This posting is provided "AS IS" with no warranties, and confers no rights.
as you said, "the usual workaround is to use JSON structures instead.."
do you have a sample example to show us, please?
I would love to see a nice workaround, thank you~
Instead of exchanging class instances between the frames or windows, send a structure such as {property1: "value1", property2: 42}. In other words, instead of exchanging instance, exchange messages. Does that help?
Bertrand
----
This posting is provided "AS IS" with no warranties, and confers no rights.
jawc
Member
7 Points
13 Posts
isInstanceOfType Method cause Stack Overflow at line 0...
Oct 04, 2007 06:38 AM|LINK
Hi,
I have created a very small example..
It shows stack overflow at line 0..
There are two pages which are main.aspx and inner.aspx.
There is a button in inner.aspx.
When you click the button, a javascript object will be created and pass to main.aspx.
The problem is inside main.aspx. There is a method "testOpen1" which validates type of argument...
any idea?
Main.aspx
<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">
<Scripts>
<asp:ScriptReference Path="jasonsoft.js" />
</Scripts>
</asp:ScriptManager>
<div>
<iframe width="500px" height="600px" src="inner.aspx">
</iframe>
</div>
<script type="text/javascript">
function testOpen1(arg1)
{
var typeResult1 = JasonSoft.JWindow.isInstanceOfType(arg1); //here is the problem...
alert(typeResult1);
}
</script>
</form>
</body>
</html>
inner.aspx
<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">
<Scripts>
<asp:ScriptReference Path="jasonsoft.js" />
</Scripts>
</asp:ScriptManager>
<div>
<input id="Button1" type="button" value="button" onclick="TestMe();" />
</div>
<script type="text/javascript">
function TestMe()
{
var jWin = new JasonSoft.JWindow();
top.testOpen1(jWin);
}
</script>
</form>
</body>
</html>
jasonsoft.js
/// <reference name="MicrosoftAjax.js"/>Type.registerNamespace("JasonSoft");
JasonSoft.JWindow = function () {
this._name = "Jason";
}
JasonSoft.JWindow.prototype =
{
set_Name: function(nameValue)
{
this._name = nameValue;
},
get_Name: function()
{
return this._name;
}
}
JasonSoft.JWindow.registerClass("JasonSoft.JWindow");
// Notify ScriptManager that this is the end of the script.
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
jawc
Member
7 Points
13 Posts
Re: Stack Overflow at line 0...
Oct 04, 2007 06:59 AM|LINK
I have forgot to motion I am using vs2008 beta2
jawc
Member
7 Points
13 Posts
Re: isInstanceOfType cause IStack Overflow at line 0...
Oct 07, 2007 04:15 AM|LINK
Does anyone has good suggestion, please?
Luis Abreu
All-Star
25674 Points
5369 Posts
MVP
Re: isInstanceOfType cause IStack Overflow at line 0...
Oct 07, 2007 10:02 PM|LINK
Regards,
Luis Abreu
email: labreu_at_gmail.com
EN blog:http://msmvps.com/blogs/luisabreu
jawc
Member
7 Points
13 Posts
Re: isInstanceOfType cause IStack Overflow at line 0...
Oct 08, 2007 02:00 AM|LINK
Dear Luis,
Thank you for your reply...
Yes, the problem is as you described.
They use two different javascript window objects..
Thank you for your help...^^
bleroy
All-Star
15617 Points
2302 Posts
Re: isInstanceOfType cause IStack Overflow at line 0...
Oct 08, 2007 05:24 AM|LINK
Right, this can't work, ever. Two different windows have separate copies of the type system. Except for built-in types, you can't reliably exchange objects between windows. The usual workaround is to use JSON structures instead.
----
This posting is provided "AS IS" with no warranties, and confers no rights.
jawc
Member
7 Points
13 Posts
Re: isInstanceOfType cause IStack Overflow at line 0...
Oct 09, 2007 03:08 AM|LINK
as you said, "the usual workaround is to use JSON structures instead.."
do you have a sample example to show us, please?
I would love to see a nice workaround, thank you~
bleroy
All-Star
15617 Points
2302 Posts
Re: isInstanceOfType cause IStack Overflow at line 0...
Oct 09, 2007 04:55 AM|LINK
Instead of exchanging class instances between the frames or windows, send a structure such as {property1: "value1", property2: 42}. In other words, instead of exchanging instance, exchange messages. Does that help?
----
This posting is provided "AS IS" with no warranties, and confers no rights.
jawc
Member
7 Points
13 Posts
Re: isInstanceOfType cause IStack Overflow at line 0...
Oct 09, 2007 09:55 AM|LINK
I see.....
thank you~