当前位置: 首页 > 图文教程 > 网络编程 > ASP.NET > .net中Web自定义控件编写注意事项

ASP.NET
Web服务器控件:LinkButton控件
Web服务器控件:ListBox控件
Web服务器控件:ListItem控件
Web服务器控件:Literal控件
Web服务器控件:Panel控件
Web服务器控件:PlaceHolder控件
Web服务器控件:RadioButton控件
Web服务器控件:RadioButtonList控件
Web服务器控件:BulletedList控件
Web服务器控件:Style控件
Web服务器控件:Table控件
Web服务器控件:TableCell控件
Web服务器控件:TableRow控件
Web服务器控件:TextBox控件
Web服务器控件:XML控件
Validation服务器控件:CompareValidator控件
Validation服务器控件:CustomValidator控件
Validation服务器控件:RangeValidator控件
Validation服务器控件:RegularExpressionValidator控件
Validation服务器控件:RequiredFieldValidator控件

ASP.NET 中的 .net中Web自定义控件编写注意事项


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 160 ::
收藏到网摘: n/a


  如果重载本身父类提供的enable属性,将导致无法将子控件中的值用viewstate回传,即无法保持状态。所以最好自己定义该类属性并实现。
  定义属性时,如果是子控件本身属性的反映,可以直接取其值,值将自动保留,如果属于自己定义的属性,用viewState保留状态
  例如:


  ///
  /// 文本框值 txtMD是一个Web TextBox
  ///

  [Bindable(true),
  Category("Appearance"),
  DefaultValue("")]
  public string Text
  {
  get
  {
  if(txtMD.Text!="")
  return txtMD.Text;
  else
  return "";
  }
  set
  {
  txtMD.Text=value;
  }
  }


  自定义属性:

  ///
  /// 参考录入窗口宽度
  ///

  [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是区分多个相同控件在同一页面上时的相同属性。