Ajax-метод объекта клиента, вызываемый с параметром - PullRequest
1 голос
/ 14 декабря 2010

Внутри клиентского контроля я генерирую кнопку со скриптом для запуска. Я хочу вызвать метод Print () объекта при нажатии этой кнопки, значение результата также должно быть передано Print ().

Как я могу это сделать?

Это мой объект:

Type.registerNamespace("CustomControls");

CustomControls.FirstObj = function(element) {
    CustomControls.FirstObj.initializeBase(this, [element]);

    this._targetControlDelegate === null
    this.markUp = '<div><input type="button" id="theButton" value="Button!" onclick="Foo()"/><script type="text/javascript">function Foo() {return "result";}</script></div>';

}
CustomControls.FirstObj.prototype = {  

    dispose: function() {              
        CustomControls.FirstObj.callBaseMethod(this, 'dispose');
    },

    initialize: function() {

           var div;
           div = document.createElement('div');
           div.name = div.id = "divName";


           div.innerHTML = this.markUp;           
           document.body.appendChild(div);      

           var targetControl = $get("theButton");
//            if (targetControl != null) {
//                if (this._targetControlDelegate === null) {
//                    this._targetControlDelegate = Function.createDelegate(this, this._targetControlHandler);
//                }
//                Sys.UI.DomEvent.addHandler(targetControl, 'click', this._targetControlDelegate);
//            }
        CustomControls.FirstObj.callBaseMethod(this, 'initialize');

    },
//    _targetControlHandler: function(event) {
//         
//       
//    },

    _Print: function(result) {
       //Alert Result
    },


}
CustomControls.FirstObj.registerClass('CustomControls.FirstObj', Sys.UI.Control);
if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

Обновление:
Я думаю, что нет решения для моей проблемы.
Может быть, есть альтернативный подход, который вы можете предложить?

1 Ответ

0 голосов
/ 15 декабря 2010

Один из способов - сохранить объект FirstObj в свойстве только что созданной кнопки:

initialize: function() {
    var div = document.createElement("div");
    div.name = div.id = "divName";
    div.innerHTML = this.markUp;
    document.body.appendChild(div);

    var targetControl = $get("theButton");
    targetControl.__firstObj = this;

    CustomControls.FirstObj.callBaseMethod(this, 'initialize');
}

Это позволит вам использовать это свойство для ссылки на объект FirstObj внутри вашей разметки:

CustomControls.FirstObj = function(element) {
    CustomControls.FirstObj.initializeBase(this, [element]);

    this._targetControlDelegate = null;
    this.markUp = '<div><input type="button" id="theButton" value="Button!"'
        + 'onclick="this.__firstObj._Print(Foo());" />'
        + '<script type="text/javascript">function Foo() {return "result";}'
        + '</script></div>';
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...