2011-01-20 50 views
0

我C#4.0中的VS 2010幫助調試一個Ajax服務器控件的客戶端腳本

寫在ASP.NET一個Ajax服務器控件手寫的JavaScript原型下課後,我不知道的方式來編譯和調試文件。看看爲什麼我的「onclick」事件不起作用。

我正在通過繼承控件& 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(); 
+0

爲什麼「用JavaScript編寫JavaScript原型類」?爲什麼不使用原型(如果需要)? – user492238 2011-01-20 05:11:36

回答

1

如果你可以使用Firefox,下載Firebug extension。加載頁面時,右鍵單擊您創建的元素並選擇「檢查元素」。通過這種方式,您可以查看當前存在的DOM的所有結構,屬性和功能。在使用JavaScript時,這通常比「查看源代碼」更可取。您應該能夠看到在JavaScript調試器中綁定了哪些事件處理程序並設置了斷點。

相關問題