[英]How to attach element to another Ajax component
全部,请原谅我对ASP.NET Ajax不熟悉。 我知道Create方法将html元素附加到ajax组件。 但是我不知道如何将其与当前组件分离。 并附上另一个。
假设有一个元素ctl00_PlaceHolderMain_UserRegistration_txbPassword1
已附加到组件类型AccelaWebControlExtender.HelperBehavior
,并且创建的组件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检索组件,然后执行分离和附加工作。 希望有人能给我一些帮助。
经过研究,我发现它被称为Extend Web server control that encapsulates a client behavior
在Asp.net Ajax中,并且我发现组件的附件是由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();
我认为我们可以重写Javascript Object Samples.FocusBehavior
及其某些原型对象的方法来实现自定义。
例如 。
我可以像这样在脚本中覆盖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;
}
};
只要确保此代码在原始代码之后被浏览器解析即可。
我不确定这是否是正确的方法。 希望有人可以帮助您进行验证。非常感谢。
这是一个教程 。 请检查一下。 干杯。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.