【发布时间】:2011-01-20 05:06:06
【问题描述】:
我正在 VS 2010 的 ASP.NET C# 4.0 中编写 Ajax 服务器控件。
手工写完javascript原型类后,不知道编译调试文件的方法。看看为什么我的“onclick”事件不起作用。
我正在通过从 Control 和 IScriptControl 继承来创建 Ajax 服务器控件,并尝试让 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();
【问题讨论】:
-
为什么要“手工编写javascript原型类”?为什么不使用原型(如果需要)?
-
为什么要搜索“编译和调试文件的方法”?哪个文件?为什么要编译它? java脚本没有编译?
-
首先检查发送到浏览器的 html。为此流行的是firefox中的firebug。查看有问题的 html 元素。看看你的处理程序是否安装正确。我想它不是。然后回到 asp 并开始在那里挖掘。
-
对不起,我应该说原型的智能感知..不编译...我试试看是否安装了处理程序...谢谢