0

我在 ASP .NET 中扩展ExtenderControlBase控件。它被称为:

public class LookupExtender : ExtenderControlBase

基本上它在类似于自动完成功能的东西中所做的 - 但是是静态的。LookupExtender 具有指定的TypeNameListName属性:

  • 具有string[] GetList(string listName)方法的类
  • 将传递给 GetList 方法的列表的名称

现在,LookupExtender 动态创建TypeName实例(反射),调用GetList方法,我想将string[]结果作为数组呈现给客户端,以便扩展器客户端代码具有用于自动建议的静态源。

有没有办法从LookupExtender类呈现 JavaScript?

这是我的示例代码(当前自动建议值是硬编码的):

set_TargetTextBoxID: function (value) {
    this._targetTextBoxID = value;

    $(function () {
        var availableTags = [
            "Switzerland",
            "Poland",
            "Europe",
            "USA",
            "Asia"
        ];
        $("#" + value).autocomplete({
            source: availableTags,
            minLength: 0,
            close: function () {
                $(this).blur();
            }
        }).focus(function () {
            $(this).autocomplete("search", "");
        });
    });
}
4

1 回答 1

0

结果很容易

  • 扩展器的服务器端:

    protected override void RenderInnerScript(ScriptBehaviorDescriptor descriptor)
    {
        var listSource = System.Reflection.Assembly.GetExecutingAssembly().CreateInstance(SourceType) as ILookupExtenderListSource;
        if (listSource == null) return;
    
        var lookupList = listSource.GetList(SourceList);
        descriptor.AddProperty("LookupArray", lookupList);
    }
    
  • 客户端js脚本:

CIPNet.Extenders.LookupBehavior.prototype = { 初始化:function() { CIPNet.Extenders.LookupBehavior.callBaseMethod(this, 'initialize'); },

dispose: function() {
    CIPNet.Extenders.LookupBehavior.callBaseMethod(this, 'dispose');
},

//
// Property accessors 
//

get_LookupArray: function() {
    return this._lookupArray;
},

set_LookupArray: function(value) {
    this._lookupArray = value;
},

get_TargetTextBoxID: function() {
    return this._targetTextBoxID;
},

set_TargetTextBoxID: function(value) {
    this._targetTextBoxID = value;
    var that = this;

    $(function() {

        var showSuggestion = function () {
            $(this).autocomplete("search", "");
        };

        var availableTags = that._lookupArray;
        $("#" + value).autocomplete({
            source: availableTags,
            delay: 0,
            minLength: 0
        }).click(showSuggestion);
    });
}

};

于 2012-07-18T10:27:28.273 回答