浙林龙哥

   :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
 

  如果重载本身父类提供的enable属性,将导致无法将子控件中的值用viewstate回传,即无法保持状态。所以最好自己定义该类属性并实现。

  定义属性时,如果是子控件本身属性的反映,可以直接取其值,值将自动保留,如果属于自己定义的属性,用viewState保留状态

  例如:

   /// <summary>
  /// 文本框值 txtMD是一个Web TextBox

  /// </summary>

  [Bindable(true),

  Category("Appearance"),

  DefaultValue("")]

  public string Text

  {

  get

  {

  if(txtMD.Text!="")

  return txtMD.Text;

  else

  return "";

  }

  set

  {               

  txtMD.Text=value;

  }

  }
 

  自定义属性:


   /// <summary>
  /// 参考录入窗口宽度

  /// </summary>

  [Bindable(true),

  Category("Appearance"),

  DefaultValue("50")]

  public int TextBoxMaxLength

  {

  get

  {

  return ViewState[this.UniqueID+"TextBoxMaxLength"]==null?50:(int)ViewState[this.UniqueID+"TextBoxMaxLength"];

  }

  set

  {

  ViewState[this.UniqueID+"TextBoxMaxLength"]=value;

  }

  }

  注意:加上this.UniqueID是区分多个相同控件在同一页面上时的相同属性。 

  如果重载本身父类提供的enable属性,将导致无法将子控件中的值用viewstate回传,即无法保持状态。所以最好自己定义该类属性并实现。

  定义属性时,如果是子控件本身属性的反映,可以直接取其值,值将自动保留,如果属于自己定义的属性,用viewState保留状态

  例如:

   /// <summary>
  /// 文本框值 txtMD是一个Web TextBox

  /// </summary>

  [Bindable(true),

  Category("Appearance"),

  DefaultValue("")]

  public string Text

  {

  get

  {

  if(txtMD.Text!="")

  return txtMD.Text;

  else

  return "";

  }

  set

  {               

  txtMD.Text=value;

  }

  }
 

  自定义属性:


   /// <summary>
  /// 参考录入窗口宽度

  /// </summary>

  [Bindable(true),

  Category("Appearance"),

  DefaultValue("50")]

  public int TextBoxMaxLength

  {

  get

  {

  return ViewState[this.UniqueID+"TextBoxMaxLength"]==null?50:(int)ViewState[this.UniqueID+"TextBoxMaxLength"];

  }

  set

  {

  ViewState[this.UniqueID+"TextBoxMaxLength"]=value;

  }

  }

  注意:加上this.UniqueID是区分多个相同控件在同一页面上时的相同属性。 

作者:qiuchun
来源:csdn.net

posted on 2004-12-03 10:08  浙林龙哥  阅读(784)  评论(0编辑  收藏  举报