0

ASP .NET でExtenderControlBaseコントロールを拡張しています。それは呼ばれています:

public class LookupExtender : ExtenderControlBase

基本的に、オートコンプリート機能に似たものですが、静的です。LookupExtender には、次を指定するTypeNameおよびListName属性があります。

  • 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 = { initialize: 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 に答える