2013-06-13 5 views
0

모두 감사합니다. ASP.NET Ajax에 익숙하지 않습니다. Create 메소드가 html 요소를 ajax 구성 요소에 연결하는 것을 알고있었습니다. 하지만 현재 구성 요소에서 분리하는 방법을 모르겠습니다. 다른 하나를 첨부하십시오.다른 Ajax 구성 요소에 요소를 연결하는 방법

ctl00_PlaceHolderMain_UserRegistration_txbPassword1 요소가 연결되어 있고 생성 된 구성 요소 ID가 ctl00_PlaceHolderMain_UserRegistration_txbPassword1_helper_bhv 인 경우를 예로 들어 보겠습니다. 코드는 다음과 같습니다. 검토해주십시오.

Sys.Application.add_init(function() { 
    $create(AccelaWebControlExtender.HelperBehavior, {"closeTitle":"Close","id":"ctl00_PlaceHolderMain_UserRegistration_txbPassword1_helper_bhv","isRTL":false,"title":"Help"}, null, null, $get("ctl00_PlaceHolderMain_UserRegistration_txbPassword1")); 
}); 

먼저 ID로 구성 요소를 검색 한 다음 분리 및 연결 작업을 수행해야한다고 생각합니다. 누군가가 나를 도와 줄 수 있기를 바랍니다. 감사합니다.

답변

1

일부 연구를 한 후, 나는 Asp.net Ajax에서 Extend Web server control that encapsulates a client behavior이라고 불렀다. 그리고 컴포넌트의 첨부 파일이 Asp.net에 의해 자동으로 수행된다는 것을 알았다. 우리는 Sys.Application.add_init(function() 코드가 자동으로 Asp.net에 의해 aspx 페이지에서 생성 된 것을 볼 수 있습니다. 따라서 Web Server Control의 원래 동작을 사용자 지정하려는 경우 Javascript OOP 방식 (이전 및 동일)으로 만들 수 있다고 생각합니다.

예 : 원래 동작 코드가 손상된 경우.

// Register the namespace for the control. 
Type.registerNamespace('Samples'); 

// 
// Define the behavior properties. 
// 
Samples.FocusBehavior = function(element) { 
    Samples.FocusBehavior.initializeBase(this, [element]); 

    this._highlightCssClass = null; 
    this._nohighlightCssClass = null; 
} 

// 
// Create the prototype for the behavior. 
// 
Samples.FocusBehavior.prototype = { 
    initialize : function() { 
     Samples.FocusBehavior.callBaseMethod(this, 'initialize'); 

     $addHandlers(this.get_element(), 
        { 'focus' : this._onFocus, 
         'blur' : this._onBlur }, 
        this); 

     this.get_element().className = this._nohighlightCssClass; 
    }, 

    dispose : function() { 
     $clearHandlers(this.get_element()); 

     Samples.FocusBehavior.callBaseMethod(this, 'dispose'); 
    }, 

    // 
    // Event delegates 
    // 
    _onFocus : function(e) { 
     if (this.get_element() && !this.get_element().disabled) { 
      this.get_element().className = this._highlightCssClass;   
     } 
    }, 

    _onBlur : function(e) { 
     if (this.get_element() && !this.get_element().disabled) { 
      this.get_element().className = this._nohighlightCssClass;   
     } 
    }, 


    // 
    // Behavior properties 
    // 
    get_highlightCssClass : function() { 
     return this._highlightCssClass; 
    }, 

    set_highlightCssClass : function(value) { 
     if (this._highlightCssClass !== value) { 
      this._highlightCssClass = value; 
      this.raisePropertyChanged('highlightCssClass'); 
     } 
    }, 

    get_nohighlightCssClass : function() { 
     return this._nohighlightCssClass; 
    }, 

    set_nohighlightCssClass : function(value) { 
     if (this._nohighlightCssClass !== value) { 
      this._nohighlightCssClass = value; 
      this.raisePropertyChanged('nohighlightCssClass'); 
     } 
    } 
} 

// Optional descriptor for JSON serialization. 
Samples.FocusBehavior.descriptor = { 
    properties: [ {name: 'highlightCssClass', type: String}, 
        {name: 'nohighlightCssClass', type: String} ] 
} 

// Register the class as a type that inherits from Sys.UI.Control. 
Samples.FocusBehavior.registerClass('Samples.FocusBehavior', Sys.UI.Behavior); 

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

나는 우리가 자바 스크립트 객체 Samples.FocusBehavior의 메소드의 일부를 오버라이드 (override) 할 수 있다고 생각하고 그것을 사용자 정의를 달성하기 위해 프로토 타입 객체를합니다.

예를 들면.

이렇게 스크립트에서 Samples.FocusBehavior.prototype._onFocus을 덮어 쓸 수 있습니다.

Samples.FocusBehavior.prototype._onFocus = function (e) { 
    alert('test'); 
    if (this.get_element() && !this.get_element().disabled) { 
     this.get_element().className = this._highlightCssClass; 
    } 
}; 

이 코드가 브라우저에서 원래 코드로 구문 분석되었는지 확인하십시오.
이것이 올바른 방법인지 확실하지 않습니다. 누군가가 그것을 확인하는 데 도움이되기를 바랍니다. 감사합니다.

여기에 tutorial입니다. 검토해주십시오. 건배.

관련 문제