zoukankan      html  css  js  c++  java
  • .net中Web自定义控件编写注意事项

     

      如果重载本身父类提供的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

  • 相关阅读:
    Codeforces Round #630 (Div. 2) E. Height All the Same(组合数学 快速幂 逆元)
    Codeforces Round #627 (Div. 3) F. Maximum White Subtree(树型dp 换根法)
    Codeforces Round #630 (Div. 2) F. Independent Set (树型dp)
    权值线段树 简单总结 相关例题
    Codeforces Round #631 (Div. 2) D. Dreamoon Likes Sequences (bitmasks +dp )
    2018,奔波与意义
    geopandas overlay 函数报错问题解决方案
    使用Python实现子区域数据分类统计
    我要做数据分析
    geotrellis使用(四十二)将 Shp 文件转为 GeoJson
  • 原文地址:https://www.cnblogs.com/huqingyu/p/72348.html
Copyright © 2011-2022 走看看