| 操作系统 办公 实用知识 设计 开发 WEB开发 移动开发 数据库 软件工程 网管 安全 管理 信息化 答疑 渠道 |
.net中Web自定义控件编写注意事项如果重载本身父类提供的enable属性,将导致无法将子控件中的值用viewstate回传,即无法保持状态。所以最好自己定义该类属性并实现。 定义属性时,如果是子控件本身属性的反映,可以直接取其值,值将自动保留,如果属于自己定义的属性,用viewState保留状态 例如: /// <summary> /// </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; } }
今日推荐
|
重点推荐
领军企业技术文库
+更多领军技术文库
最新专题
电子杂志订阅
| ||||||||