简体   繁体   English

如何使用javascript从外部调用scriptcontrol内部的函数

[英]How to call a function inside a scriptcontrol from outside using javascript

I look it up for a while but couldn't find the answers I'm looking for. 我查找了一段时间,但找不到所需的答案。

I'm create an new TextBox from scratch using the IScriptControl and ScriptManager. 我使用IScriptControl和ScriptManager从头开始创建一个新的TextBox。

everything works fine inside my scriptcontrol but I'm wondering how I can trigger a function inside the scriptcontrol from outside. 一切在我的scriptcontrol内部都能正常工作,但是我想知道如何从外部触发scriptcontrol内部的函数。

to give an example. 举个例子。 Lets say I have this: 可以说我有这个:

Type.registerNamespace('QuyoDevLib.Web.UI');
    QuyoDevLib.Web.UI.InputBox = function (element) {
        QuyoDevLib.Web.UI.InputBox.initializeBase(this, [element]);
        this._element = this.get_element();

    }
    QuyoDevLib.Web.UI.InputBox.prototype = {
        initialize: function () {
            QuyoDevLib.Web.UI.InputBox.callBaseMethod(this, 'initialize');

        },
        dispose: function () {

            QuyoDevLib.Web.UI.InputBox.callBaseMethod(this, 'dispose');
        },
        doSomething: function() {
        //do something usefull
        }
    }
    QuyoDevLib.Web.UI.InputBox.registerClass('QuyoDevLib.Web.UI.InputBox', Sys.UI.Control);
    if (typeof (Sys) !== 'undefined')
        Sys.Application.notifyScriptLoaded();
$create(QuyoDevLib.Web.UI.InputBox, null, null, null, $get("TestControl"))

How can I make this underlaying javascript work to trigger the "doSomething" function inside my scriptcontrol? 如何使这种底层javascript能够触发脚本控件内的“ doSomething”功能? What I had in mind you see under here but this doesn't work I already tested it. 您在这里看到的我想到的内容,但是我已经对其进行了测试,但是它不起作用。

<script>
    function test() {
       $get("TestControl").doSomething();
    }
    </script>

k I looked a bit more and found my own solution. k我多了一点,找到了自己的解决方案。

I share it here so everyone with the same question or problem can use it. 我在这里分享它,以便每个有相同问题的人都可以使用。

I had to change $get into $find to make it work. 我必须将$ get更改为$ find才能起作用。

<script>
        function test() {
           $get("TestControl").doSomething();
        }
        </script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM