帮助调试 Ajax 服务器控制客户端脚本

发布于 2024-10-13 02:42:04 字数 2262 浏览 2 评论 0原文

我正在 VS 2010 中的 ASP.NET C# 4.0 中编写一个 Ajax 服务器控件。

手工编写 javascript 原型类后,我不知道如何编译和调试文件。看看为什么我的“onclick”事件不起作用。

我正在通过继承 Control & 来创建 Ajax 服务器控件。 IScriptControl,并尝试让 onclick 事件处理程序正常工作。写的控件实际上是一个“DIV”。有人能告诉我为什么它不起作用吗?

谢谢

public class FrebbleSquare : Control, IScriptControl 
    {
.
.
.
IEnumerable<ScriptReference> IScriptControl.GetScriptReferences()
        {
            ScriptReference oRef1 = new ScriptReference("FrebbleAjaxControls.FrebbleSquare.js", this.GetType().Assembly.ToString());
            ScriptReference oRef2 = new ScriptReference("FrebbleAjaxControls.prototype.js", this.GetType().Assembly.ToString());
            ScriptReference oRef3 = new ScriptReference("FrebbleAjaxControls.scriptaculous.js", this.GetType().Assembly.ToString());
            ScriptReference oRef4 = new ScriptReference("FrebbleAjaxControls.effects.js", this.GetType().Assembly.ToString());

            return new ScriptReference[] { oRef1, oRef2, oRef3, oRef4 };
        }


        IEnumerable<ScriptDescriptor> IScriptControl.GetScriptDescriptors()
        {
            ScriptControlDescriptor descriptor = new ScriptControlDescriptor("FrebblesAjax.FrebbleSquare", this.ClientID);

            return new ScriptDescriptor[] { descriptor };
        }

}


JAVASCRIPT CLIENT FILE :


Type.registerNamespace('FrebblesAjax');

FrebblesAjax.FrebbleSquare = function (element) {

    FrebblesAjax.FrebbleSquare.initializeBase(this, [element]);


}


FrebblesAjax.FrebbleSquare.prototype =
{
    initialize: function () {

        FrebblesAjax.FrebbleSquare.callBaseMethod(this, 'initialize');

        this._onclickHandler = Function.createDelegate(this, this._onClick);

        $addHandlers(this.get_element(),
                     { 'click': this._onClick,
                     },
                     this);

    },

    dispose: function () {

        $clearHandlers(this.get_element());

        FrebblesAjax.FrebbleSquare.callBaseMethod(this, 'dispose');
    },

    _onClick: function (e) {

        alert('it worked!');

    }

}


FrebblesAjax.FrebbleSquare.registerClass('FrebblesAjax.FrebbleSquare', Sys.UI.Control);

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

I am writing an Ajax Server Control in ASP.NET C# 4.0 in VS 2010.

After writing the javascript prototype class by hand, I don't know of a way to compile and debug file. To see why my "onclick" event doesn't work.

I'm creating an Ajax Server control by inheriting from Control & IScriptControl, and trying to get an onclick event handler to work. The written control is actually a "DIV". Can someone tell me why it doesn't work?

Thanks

public class FrebbleSquare : Control, IScriptControl 
    {
.
.
.
IEnumerable<ScriptReference> IScriptControl.GetScriptReferences()
        {
            ScriptReference oRef1 = new ScriptReference("FrebbleAjaxControls.FrebbleSquare.js", this.GetType().Assembly.ToString());
            ScriptReference oRef2 = new ScriptReference("FrebbleAjaxControls.prototype.js", this.GetType().Assembly.ToString());
            ScriptReference oRef3 = new ScriptReference("FrebbleAjaxControls.scriptaculous.js", this.GetType().Assembly.ToString());
            ScriptReference oRef4 = new ScriptReference("FrebbleAjaxControls.effects.js", this.GetType().Assembly.ToString());

            return new ScriptReference[] { oRef1, oRef2, oRef3, oRef4 };
        }


        IEnumerable<ScriptDescriptor> IScriptControl.GetScriptDescriptors()
        {
            ScriptControlDescriptor descriptor = new ScriptControlDescriptor("FrebblesAjax.FrebbleSquare", this.ClientID);

            return new ScriptDescriptor[] { descriptor };
        }

}


JAVASCRIPT CLIENT FILE :


Type.registerNamespace('FrebblesAjax');

FrebblesAjax.FrebbleSquare = function (element) {

    FrebblesAjax.FrebbleSquare.initializeBase(this, [element]);


}


FrebblesAjax.FrebbleSquare.prototype =
{
    initialize: function () {

        FrebblesAjax.FrebbleSquare.callBaseMethod(this, 'initialize');

        this._onclickHandler = Function.createDelegate(this, this._onClick);

        $addHandlers(this.get_element(),
                     { 'click': this._onClick,
                     },
                     this);

    },

    dispose: function () {

        $clearHandlers(this.get_element());

        FrebblesAjax.FrebbleSquare.callBaseMethod(this, 'dispose');
    },

    _onClick: function (e) {

        alert('it worked!');

    }

}


FrebblesAjax.FrebbleSquare.registerClass('FrebblesAjax.FrebbleSquare', Sys.UI.Control);

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

爱的十字路口 2024-10-20 02:42:04

如果您可以使用 Firefox,请下载 Firebug 扩展。页面加载后,右键单击您创建的元素并选择“检查元素”。这样您就可以看到 DOM 当前存在的所有结构、属性和功能。当您使用 JavaScript 时,这通常比“查看源代码”更好。您应该能够查看绑定了哪些事件处理程序并在 JavaScript 调试器中设置断点。

If you can use Firefox, download the Firebug extension. When the page loads, right-click on the element that you created and select "inspect element". This way you can see all the structure, properties, and functions of the DOM as it currently exists. This is usually preferable to "view source" when you're working with JavaScript. You should be able to see which event handlers are bound and set breakpoints in the JavaScript debugger.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文