Je souhaite passer la référence du premier objet créé (réf à l'objet initialisé) à un autre et appeler la méthode Print.Création d'un contrôle client AJAX personnalisé à l'intérieur d'un autre client AJAX Control et envoi du premier en tant que réf
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();