2005-01-31 Zoltan Varga <vargaz@freemail.hu>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / BaseDataBoundControl.cs
1 //
2 // System.Web.UI.WebControls.BaseDataBoundControl.cs
3 //
4 // Authors:
5 //      Lluis Sanchez Gual (lluis@novell.com)
6 //
7 // (C) 2004 Novell, Inc (http://www.novell.com)
8 //
9
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 #if NET_2_0
32 using System.Collections;
33
34 namespace System.Web.UI.WebControls
35 {
36         public abstract class BaseDataBoundControl: WebControl
37         {
38                 public event EventHandler DataBound;
39                 
40                 object dataSource;
41                 string dataSourceId;
42                 bool initialized;
43                 bool requiresDataBinding = true;
44                 
45                 public virtual object DataSource {
46                         get {
47                                 return dataSource;
48                         }
49                         set {
50                                 ValidateDataSource (value);
51                                 dataSource = value;
52                         }
53                 }
54                 
55                 public virtual string DataSourceID {
56                         get { return dataSourceId; }
57                         set { dataSourceId = value; }
58                 }
59                 
60                 protected bool Initialized {
61                         get { return initialized; }
62                 }
63                 
64                 [MonoTODO]
65                 protected bool IsBoundUsingDataSourceID {
66                         get { return dataSourceId != null; }
67                 }
68                 
69                 protected bool RequiresDataBinding {
70                         get { return requiresDataBinding; }
71                         set { requiresDataBinding = value; }
72                 }
73                 
74                 [MonoTODO]
75                 protected void ConfirmInitState ()
76                 {
77                 }
78                 
79                 public override void DataBind ()
80                 {
81                         PerformSelect ();
82                         RequiresDataBinding = false;
83                         OnDataBound (EventArgs.Empty);
84                 }
85                 
86                 protected void EnsureDataBound ()
87                 {
88                         if (RequiresDataBinding && DataSourceID != "")
89                                 DataBind ();
90                 }
91                 
92                 protected virtual void OnDataBound (EventArgs e)
93                 {
94                         if (DataBound != null)
95                                 DataBound (this, e);
96                 }
97                 
98                 [MonoTODO]
99                 protected virtual void OnDataPropertyChanged ()
100                 {
101                 }
102                 
103                 [MonoTODO]
104                 protected override void OnInit (EventArgs e)
105                 {
106                         base.OnInit (e);
107                         initialized = true;
108                         if (!Page.IsPostBack)
109                                 RequiresDataBinding = true;
110                 }
111                 
112                 [MonoTODO]
113                 protected virtual void OnPagePreLoad (object sender, EventArgs e)
114                 {
115                 }
116                 
117                 protected override void OnPreRender (EventArgs e)
118                 {
119                         EnsureDataBound ();
120                         base.OnPreRender (e);
121                 }
122                 
123                 protected abstract void PerformSelect ();
124                 
125                 protected abstract void ValidateDataSource (object dataSource);
126                 
127         }
128 }
129
130 #endif
131