1.WebResource
  获取一个字符串,该字符串包含由 WebResourceAttribute 类所引用的资源的名称。
 [assembly: WebResource( "Aerolite.Resources.Js.SearchTextBox.js", "application/x-javascript" )]
[assembly: WebResource( "Aerolite.Resources.Js.SearchTextBox.js", "application/x-javascript" )] [assembly: WebResource( "Aerolite.Resources.Js.MenuCommon.js", "application/x-javascript" )]
[assembly: WebResource( "Aerolite.Resources.Js.MenuCommon.js", "application/x-javascript" )]2.TagPrefix
定义在网页中用于标识自定义控件的标记前缀。
 [assembly: TagPrefix( "Aerolite.Web.WebControls", "arl" )]
[assembly: TagPrefix( "Aerolite.Web.WebControls", "arl" )]
3.ToolboxData
指定当从MS等工具的工具箱拖动自定义控件时为它生成的默认标记
 [ToolboxData( "<{0}:SearchTextBox runat=server />" )]
  [ToolboxData( "<{0}:SearchTextBox runat=server />" )]
4.ParseChildren
定义可在开发asp.net服务器控件时使用的元数据属性
 [ParseChildren( true )]
 [ParseChildren( true )] 5.Bindable
指示成员是否用于绑定
6.Themeable
获取一个值,该值指示当前控件或控件的成员是否受 Web 应用程序中定义的主题和控件外观影响。
7.Browsable
获取一个值,该值指示此对象是否可浏览。是否显示在“属性”窗口中。
 [Bindable( true ), Themeable( false ), Browsable( true )]
 [Bindable( true ), Themeable( false ), Browsable( true )] 8.Category
指定当属性或者事件显示在一个设置为"按分类顺序"模式的System.Windows.Forms.PropertyGrid控件中时,用于给属性或事件分组的类别的名称。
9.DefaultValue
属性的默认值
10.Localizable
属性是否应本地化.
 [Category( "Data" )]
   [Category( "Data" )]   [DefaultValue( "App_Code" )]
    [DefaultValue( "App_Code" )] [Localizable( true )]
    [Localizable( true )]上面是一些属性的设置,下面附封装google suggest控件的代码。
 using System;
using System; using System.Collections.Generic;
using System.Collections.Generic; using System.ComponentModel;
using System.ComponentModel; using System.Text;
using System.Text; using System.Web;
using System.Web; using System.Web.UI;
using System.Web.UI; using System.Web.UI.WebControls;
using System.Web.UI.WebControls; using System.IO;
using System.IO;
 //引用两个js文件,该js文件是生成该控件的
//引用两个js文件,该js文件是生成该控件的 [assembly: WebResource( "Aerolite.Resources.Js.SearchTextBox.js", "application/x-javascript" )]
[assembly: WebResource( "Aerolite.Resources.Js.SearchTextBox.js", "application/x-javascript" )] [assembly: WebResource( "Aerolite.Resources.Js.MenuCommon.js", "application/x-javascript" )]
[assembly: WebResource( "Aerolite.Resources.Js.MenuCommon.js", "application/x-javascript" )]
 //定义在网页中的标记前缀为arl
//定义在网页中的标记前缀为arl [assembly: TagPrefix( "Aerolite.Web.WebControls", "arl" )]
[assembly: TagPrefix( "Aerolite.Web.WebControls", "arl" )]
 namespace Aerolite.Web.WebControls
namespace Aerolite.Web.WebControls {
{ /// <summary>
  /// <summary> /// 一个可以异步传输已进行右模糊搜索的文本输入框
  /// 一个可以异步传输已进行右模糊搜索的文本输入框 /// </summary>
  /// </summary>  
 // 指定当从工具箱拖动时为它生成的默认标记
  // 指定当从工具箱拖动时为它生成的默认标记  [ToolboxData( "<{0}:SearchTextBox runat=server />" )]
  [ToolboxData( "<{0}:SearchTextBox runat=server />" )]
 //定义开发服务器控件时使用的元数据属性
  //定义开发服务器控件时使用的元数据属性 [ParseChildren( true )]
  [ParseChildren( true )]
 //定义一个属性
  //定义一个属性 [PersistChildren( false )]
  [PersistChildren( false )] public class SearchTextBox : System.Web.UI.WebControls.TextBox, System.Web.UI.ICallbackEventHandler
  public class SearchTextBox : System.Web.UI.WebControls.TextBox, System.Web.UI.ICallbackEventHandler {
  { /// <summary>
    /// <summary> /// 获取或设置提供搜索结果的类的全名
    /// 获取或设置提供搜索结果的类的全名 /// </summary>
    /// </summary> [Bindable( true ), Themeable( false ), Browsable( true )]
    [Bindable( true ), Themeable( false ), Browsable( true )] [Category( "Data" )]
    [Category( "Data" )] [DefaultValue( "" )]
    [DefaultValue( "" )] [Localizable( true )]
    [Localizable( true )] public string DataSourceFullName
    public string DataSourceFullName {
    { get
      get {
      { return (ViewState["DataSourceFullName"] == null) ? "" : (string) ViewState["DataSourceFullName"];
        return (ViewState["DataSourceFullName"] == null) ? "" : (string) ViewState["DataSourceFullName"]; }
      } set
      set {
      { ViewState["DataSourceFullName"] = value;
        ViewState["DataSourceFullName"] = value; }
      } }
    }
 /// <summary>
    /// <summary> /// 获取或设置提供搜索结果的类所在程序集的名称
    /// 获取或设置提供搜索结果的类所在程序集的名称 /// </summary>
    /// </summary>                               [Bindable( true ), Themeable( false ), Browsable( true )]
    [Bindable( true ), Themeable( false ), Browsable( true )]    [Category( "Data" )]
    [Category( "Data" )]   [DefaultValue( "App_Code" )]
    [DefaultValue( "App_Code" )] [Localizable( true )]
    [Localizable( true )] public string DataSourceAssembly
    public string DataSourceAssembly {
    { get
      get {
      { return (ViewState["DataSourceAssembly"] == null) ? "App_Code" : (string) ViewState["DataSourceAssembly"];
        return (ViewState["DataSourceAssembly"] == null) ? "App_Code" : (string) ViewState["DataSourceAssembly"]; 
     }
      } set
      set {
      { ViewState["DataSourceAssembly"] = value;
        ViewState["DataSourceAssembly"] = value; }
      } }
    }
 /// <summary>
    /// <summary> /// 获取或设置提供搜索结果的方法的名称。
    /// 获取或设置提供搜索结果的方法的名称。 /// </summary>
    /// </summary> [Bindable( true ), Themeable( false ), Browsable( true )]
    [Bindable( true ), Themeable( false ), Browsable( true )] [Category( "Data" )]
    [Category( "Data" )] [DefaultValue( "" )]
    [DefaultValue( "" )] [Localizable( true )]
    [Localizable( true )] public string GetDataMethod
    public string GetDataMethod {
    { get
      get {
      { return (ViewState["GetDataMethod"] == null) ? "" : (string) ViewState["GetDataMethod"];
        return (ViewState["GetDataMethod"] == null) ? "" : (string) ViewState["GetDataMethod"]; }
      } set
      set {
      { ViewState["GetDataMethod"] = value;
        ViewState["GetDataMethod"] = value; }
      } }
    }
 private object _DataSource;
    private object _DataSource; [Bindable( true ), Themeable( false ), Browsable( false )]
    [Bindable( true ), Themeable( false ), Browsable( false )] public object DataSource
    public object DataSource {
    { get
      get {
      { if ( _DataSource == null )
        if ( _DataSource == null ) {
        { OnDataSourceCreating();
          OnDataSourceCreating(); }
        } return _DataSource;
        return _DataSource; }
      } set
      set {
      { _DataSource = value;
        _DataSource = value;
 Properties.Resources;
        Properties.Resources; }
      }
 
      }
    }
 public delegate void DataSoucreEventHandler( SearchTextBox sender );
    public delegate void DataSoucreEventHandler( SearchTextBox sender );
 [Bindable( false ), Browsable( false )]
    [Bindable( false ), Browsable( false )] public event DataSoucreEventHandler DataSourceCreating;
    public event DataSoucreEventHandler DataSourceCreating;
 protected virtual void OnDataSourceCreating()
    protected virtual void OnDataSourceCreating() {
    { if ( DataSourceCreating != null )
      if ( DataSourceCreating != null ) {
      { DataSourceCreating( this );
        DataSourceCreating( this ); }
      } else
      else {
      { _DataSource = System.Type.GetType( DataSourceFullName + "," + DataSourceAssembly ).InvokeMember( "", System.Reflection.BindingFlags.CreateInstance, null, null, null );
        _DataSource = System.Type.GetType( DataSourceFullName + "," + DataSourceAssembly ).InvokeMember( "", System.Reflection.BindingFlags.CreateInstance, null, null, null ); }
      } }
    }
 /// <summary>
    /// <summary> /// 定义用于获取搜索上下文菜单项的方法
    /// 定义用于获取搜索上下文菜单项的方法 /// </summary>
    /// </summary> /// <param name="searchKey">搜索框中输入的部分关键字</param>
    /// <param name="searchKey">搜索框中输入的部分关键字</param> /// <returns>构成上下文菜单的项</returns>
    /// <returns>构成上下文菜单的项</returns> public delegate string[] GetSearchResultMethod( string searchKey );
    public delegate string[] GetSearchResultMethod( string searchKey );
 private GetSearchResultMethod _getResult;
    private GetSearchResultMethod _getResult; /// <summary>
    /// <summary> /// 设置用于获取搜索上下文菜单项的方法
    /// 设置用于获取搜索上下文菜单项的方法 /// </summary>
    /// </summary> [Bindable( false ), Themeable( false ), Browsable( false )]
    [Bindable( false ), Themeable( false ), Browsable( false )] public GetSearchResultMethod GetResultMethod
    public GetSearchResultMethod GetResultMethod {
    { set
      set {
      { if ( value == null )
        if ( value == null ) throw new ArgumentNullException( "value" );
          throw new ArgumentNullException( "value" ); _getResult = value;
        _getResult = value; }
      } }
    }
 private string[] _GetResult( string searchKey )
    private string[] _GetResult( string searchKey ) {
    { if ( _getResult == null )
      if ( _getResult == null ) return GetResult( searchKey );
        return GetResult( searchKey ); else
      else return _getResult( searchKey );
        return _getResult( searchKey ); }
    }

 /// <summary>
    /// <summary> /// 获取搜索上下文菜单项
    /// 获取搜索上下文菜单项 /// </summary>
    /// </summary> /// <param name="searchKey">搜索框中输入的部分关键字</param>
    /// <param name="searchKey">搜索框中输入的部分关键字</param> /// <returns>构成上下文菜单的项</returns>
    /// <returns>构成上下文菜单的项</returns> protected virtual string[] GetResult( string searchKey )
    protected virtual string[] GetResult( string searchKey ) {
    { return FormatResult( DataSource.GetType().InvokeMember( GetDataMethod, System.Reflection.BindingFlags.InvokeMethod, null, DataSource, new object[] { searchKey } ) ).Split( ',' );
      return FormatResult( DataSource.GetType().InvokeMember( GetDataMethod, System.Reflection.BindingFlags.InvokeMethod, null, DataSource, new object[] { searchKey } ) ).Split( ',' ); }
    }
 protected override void OnPreRender( EventArgs e )
    protected override void OnPreRender( EventArgs e ) {
    { base.OnPreRender( e );
      base.OnPreRender( e ); 
       Page.ClientScript.RegisterClientScriptResource( typeof( SearchTextBox ), "Aerolite.Resources.Js.MenuCommon.js" );
      Page.ClientScript.RegisterClientScriptResource( typeof( SearchTextBox ), "Aerolite.Resources.Js.MenuCommon.js" ); Page.ClientScript.RegisterClientScriptResource( typeof( SearchTextBox ), "Aerolite.Resources.Js.SearchTextBox.js" );
      Page.ClientScript.RegisterClientScriptResource( typeof( SearchTextBox ), "Aerolite.Resources.Js.SearchTextBox.js" );
 }
    }
 protected override void Render( HtmlTextWriter writer )
    protected override void Render( HtmlTextWriter writer ) {
    { base.Render( writer );
      base.Render( writer ); writer.Write( "<script language=\"javascript\">\n" );
      writer.Write( "<script language=\"javascript\">\n" ); writer.Write( "  var " + this.ClientID + "Menu=new searchTextBox();\n" );
      writer.Write( "  var " + this.ClientID + "Menu=new searchTextBox();\n" ); writer.Write( "  " + this.ClientID + "Menu.parentObj=document.getElementById(\"" + this.ClientID + "\");\n" );
      writer.Write( "  " + this.ClientID + "Menu.parentObj=document.getElementById(\"" + this.ClientID + "\");\n" );       writer.Write( "  " + this.ClientID + "Menu.bindingEvent();\n" );
      writer.Write( "  " + this.ClientID + "Menu.bindingEvent();\n" ); writer.Write( "  " + this.ClientID + "Menu.callBack=function(){\n" + Page.ClientScript.GetCallbackEventReference( this, "this.parentObj.value", "this.getCallBackResult", null ) + ";\n};\n" );
      writer.Write( "  " + this.ClientID + "Menu.callBack=function(){\n" + Page.ClientScript.GetCallbackEventReference( this, "this.parentObj.value", "this.getCallBackResult", null ) + ";\n};\n" );                 writer.Write( @"</script>" );
      writer.Write( @"</script>" ); }
    }
 protected virtual string FormatResult( object result )
    protected virtual string FormatResult( object result ) {
    { string temp = "";
      string temp = ""; if ( result is string )
      if ( result is string ) {
      { return result.ToString();
        return result.ToString(); }
      } else if ( result is System.Collections.IEnumerable )
      else if ( result is System.Collections.IEnumerable ) {
      { foreach ( object i in (System.Collections.IEnumerable) result )
        foreach ( object i in (System.Collections.IEnumerable) result ) {
        { temp += "," + i.ToString();
          temp += "," + i.ToString(); }
        } if ( temp != "" ) temp = temp.Substring( 1 );
        if ( temp != "" ) temp = temp.Substring( 1 ); }
      } else if ( result is System.Data.DataTable )
      else if ( result is System.Data.DataTable ) {
      { foreach ( System.Data.DataRow i in ((System.Data.DataTable) result).Rows )
        foreach ( System.Data.DataRow i in ((System.Data.DataTable) result).Rows ) {
        { temp += "," + i[0].ToString();
          temp += "," + i[0].ToString(); }
        } if ( temp != "" ) temp = temp.Substring( 1 );
        if ( temp != "" ) temp = temp.Substring( 1 ); }
      } return temp;
      return temp; }
    }
 //异步回调
    //异步回调 #region ICallbackEventHandler 成员
    #region ICallbackEventHandler 成员
 string ICallbackEventHandler.GetCallbackResult()
    string ICallbackEventHandler.GetCallbackResult() {
    { return string.Join( ",", _searchResult );
      return string.Join( ",", _searchResult ); }
    }
 private string[] _searchResult;
    private string[] _searchResult; void ICallbackEventHandler.RaiseCallbackEvent( string eventArgument )
    void ICallbackEventHandler.RaiseCallbackEvent( string eventArgument ) {
    { _searchResult = _GetResult( eventArgument );
      _searchResult = _GetResult( eventArgument ); }
    }
 #endregion
    #endregion }
  } }
} 
                    
                 



 
   
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号