我也抛块砖 - 关于表单/控件的通用性

刚翻阅了 金色海洋(jyk)同志的一篇基类、接口的应用,感觉还是比较好玩的,于是看了下,写点由此引发的砖~

比如一个数据库表有两个字段,分别是:城市,地址。在页面上表示的时候呢,城市用下拉框表示,地址用textbox表示。

这里呢,还是一个中心(接口IControl.cs),两个基本点(控件DuTextBox,DuDropDownList)。
先发一下代码:
IControl.cs:

Code
<!----> 1using System;
 2using System.Data;
 3using System.Configuration;
 4using System.Web;
 5using System.Web.Security;
 6using System.Web.UI;
 7using System.Web.UI.WebControls;
 8using System.Web.UI.WebControls.WebParts;
 9using System.Web.UI.HtmlControls;
10
11
12
13namespace DuControl
14{
15    /**//// <summary>
16    /// 控件接口
17    /// </summary>

18    public interface IControl
19    {
20        string DuValue
21        {
22            get;
23            set;
24        }

25
26        string DuText
27        {
28            get;
29            set;
30        }

31    }

32}

DuTextBox:

Code
<!----> 1using System;
 2using System.Data;
 3using System.Configuration;
 4using System.Web;
 5using System.Web.Security;
 6using System.Web.UI;
 7using System.Web.UI.WebControls;
 8using System.Web.UI.WebControls.WebParts;
 9using System.Web.UI.HtmlControls;
10
11
12namespace DuControl
13{
14    /**//// <summary>
15    /// DuTextBox 的摘要说明
16    /// </summary>

17    [ToolboxData("<{0}:DuTextBox runat=\"server\"></{0}:DuTextBox>")]
18    public class DuTextBox : TextBox, IControl
19    {
20        public DuTextBox()
21        
22        }

23
24        public  string DuText
25        {
26            get
27            {
28                return this.Text;
29            }

30            set
31            {
32                this.Text = value;
33            }

34        }

35
36        protected override void OnPreRender(EventArgs e)
37        {
38            //这里可以注册一些验证用的js到form上,这样在提交时自动验证。
39            //由于迷糊着要睡了,所以这块懒的写。
40            base.OnPreRender(e);
41        }

42
43        public  string DuValue
44        {
45            get
46            {
47                return this.Text;
48            }

49            set
50            {
51                this.Text = value;
52            }

53        }

54    }

55}

DuDropDownList:

Code
<!----> 1using System;
 2using System.Data;
 3using System.Configuration;
 4using System.Web;
 5using System.Web.Security;
 6using System.Web.UI;
 7using System.Web.UI.WebControls;
 8using System.Web.UI.WebControls.WebParts;
 9using System.Web.UI.HtmlControls;
10
11namespace DuControl
12{
13    /**//// <summary>
14    /// DuDropDownList 的摘要说明
15    /// </summary>

16    [ToolboxData("<{0}:DuDropDownList runat=\"server\"></{0}:DuDropDownList>")]
17    public class DuDropDownList : DropDownList, IControl
18    {
19        public DuDropDownList()
20        {
21            
22        }

23
24        protected override void OnPreRender(EventArgs e)
25        {
26            //这里可以注册一些验证用的js到form上,这样在提交时自动验证。
27            //由于迷糊着要睡了,所以这块懒的写。
28
29            base.OnPreRender(e);
30        }

31
32
33        public  string DuText
34        {
35            get
36            {
37                return this.SelectedItem.Text;
38            }

39            set
40            {
41                this.SelectedItem.Value = value;
42            }

43        }

44
45
46        public string DuValue
47

你可能感兴趣的:(UI,Web,Security)