首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >帮助调试Ajax服务器控件客户端脚本

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

Stack Overflow用户
提问于 2011-01-20 13:06:07
回答 1查看 323关注 0票数 0

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

在手工编写javascript prototype类之后,我不知道编译和调试文件的方法。来看看为什么我的"onclick“事件不起作用。

我正在通过继承control & IScriptControl来创建一个Ajax Server控件,并尝试使用onclick事件处理程序。写入的控件实际上是一个"DIV“。有人能告诉我为什么它不工作吗?

谢谢

代码语言:javascript
复制
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();
EN

回答 1

Stack Overflow用户

发布于 2011-01-20 13:40:02

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/4743625

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档