我想将第一个创建对象的引用(引用初始化对象)传递给另一个并调用Print方法。
ASPX:
<asp:ScriptManager runat="server" ID="ScriptManager01">
<scripts>
<asp:ScriptReference Path="object.js" />
<asp:ScriptReference Path="firstobj.js" />
</scripts>
</asp:ScriptManager>
<script type="text/javascript">
function pageLoad(sender, args) {
$create(CustomControls.FirstObj, { text: 'Some Text'}, null, null, $get('Button1'));
}
</script>
<button type="button" id="Button1"></button>
firstobj.js:
Type.registerNamespace("CustomControls");
// Constructor
CustomControls.FirstObj = function(element) {
CustomControls.FirstObj.initializeBase(this, [element]);
this._clickDelegate = null;
}
CustomControls.FirstObj.prototype = {
// text property accessors.
get_text: function() {
return this.get_element().innerHTML;
},
set_text: function(value) {
this.get_element().innerHTML = value;
},
// Bind and unbind to click event.
add_click: function(handler) {
this.get_events().addHandler('click', handler);
},
remove_click: function(handler) {
this.get_events().removeHandler('click', handler);
},
// Release resources before control is disposed.
dispose: function() {
var element = this.get_element();
if (this._clickDelegate) {
Sys.UI.DomEvent.removeHandler(element, 'click', this._clickDelegate);
delete this._clickDelegate;
}
CustomControls.FirstObj.callBaseMethod(this, 'dispose');
},
initialize: function() {
debugger;
var element = this.get_element();
//if (!element.tabIndex) element.tabIndex = 0;
if (this._clickDelegate === null) {
this._clickDelegate = Function.createDelegate(this, this._clickHandler);
}
Sys.UI.DomEvent.addHandler(element, 'click', this._clickDelegate);
CustomControls.FirstObj.callBaseMethod(this, 'initialize');
},
_clickHandler: function(event) {
debugger;
$create(CustomControls.Newobj, null, null, null, document);
},
_Print: function() {
alert("print");
},
}
CustomControls.FirstObj.registerClass('CustomControls.FirstObj', Sys.UI.Control);
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
object.js:
Type.registerNamespace("CustomControls");
// Constructor
CustomControls.Newobj = function(element) {
CustomControls.Newobj.initializeBase(this, [element]);
}
CustomControls.Newobj.prototype = {
// Release resources before control is disposed.
dispose: function() {
CustomControls.Newobj.callBaseMethod(this, 'dispose');
},
initialize: function() {
debugger;
//CALL PRINT OF FIRSTOBJ
CustomControls.Newobj.callBaseMethod(this, 'initialize');
},
}
CustomControls.Newobj.registerClass('CustomControls.Newobj', Sys.UI.Control);
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
答案 0 :(得分:1)
当我寻找同样的事情时,我看到了你的帖子。看起来Microsoft脚本添加了一个加载事件,该事件在加载所有脚本并创建了对象并且可以开始相互引用之后触发。