I'm trying to create another component in the component's initialize method.
When I create the component in the pageLoad stage, it works fine. But If I create the component in the Init stage, the second component's initialize method doesn't get callled.
Here's the codes.
Type.registerNamespace('Samples');
Samples.MyComponent1 = function() {
Samples.MyComponent1.initializeBase(this);
}
Samples.MyComponent1.prototype = {
initialize : function() {
Samples.MyComponent1.callBaseMethod(this, 'initialize');
$create(Samples.MyComponent2, {}, {}, {});
alert(Object.getTypeName(this) + " get initialized!");
},
dispose : function() {
alert(Object.getTypeName(this) + " get disposed!");
Samples.MyComponent1.callBaseMethod(this, 'dispose');
}
}
Samples.MyComponent1.registerClass('Samples.MyComponent1', Sys.Component);
Samples.MyComponent2 = function() {
Samples.MyComponent2.initializeBase(this);
}
Samples.MyComponent2.prototype = {
initialize : function() {
Samples.MyComponent2.callBaseMethod(this, 'initialize');
alert(Object.getTypeName(this) + " get initialized!");
},
dispose : function() {
alert(Object.getTypeName(this) + " get disposed!");
Samples.MyComponent2.callBaseMethod(this, 'dispose');
}
}
Samples.MyComponent2.registerClass('Samples.MyComponent2', Sys.Component);
if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server" >
<Scripts>
<asp:ScriptReference Path="~/scripts/Test.js" />
</Scripts>
</asp:ScriptManager>
<script type="text/javascript">
Sys.Application.add_init(pageInit);
function pageInit() {
$create(Samples.MyComponent1, {}, {}, {}, null);
}
function pageLoad() {
}
</script>
</div>
</form>
</body>
</html>