Author: mhabersack
Date: 2007-09-04 14:48:11 -0400 (Tue, 04 Sep 2007)
New Revision: 85314

Modified:
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/DataBoundControl.cs
   trunk/mcs/class/System.Web/System.Web.UI.WebControls/ListControl.cs
Log:
2007-09-04  Marek Habersack  <[EMAIL PROTECTED]>

            * DataBoundControl.cs: make sure no data binding is done after
            OnPagePreload has executed.

            * ListControl.cs: whenever a property that can affect data binding
            is set, make sure to set RequiresDataBinding.


Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog      
2007-09-04 18:07:21 UTC (rev 85313)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/ChangeLog      
2007-09-04 18:48:11 UTC (rev 85314)
@@ -1,3 +1,11 @@
+2007-09-04  Marek Habersack  <[EMAIL PROTECTED]>
+
+       * DataBoundControl.cs: make sure no data binding is done after
+       OnPagePreload has executed.
+
+       * ListControl.cs: whenever a property that can affect data binding
+       is set, make sure to set RequiresDataBinding.
+
 2007-08-31  Marek Habersack  <[EMAIL PROTECTED]>
 
        * GridView.cs: instead of not adding hidden fields to the rows,

Modified: 
trunk/mcs/class/System.Web/System.Web.UI.WebControls/DataBoundControl.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/DataBoundControl.cs    
2007-09-04 18:07:21 UTC (rev 85313)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/DataBoundControl.cs    
2007-09-04 18:48:11 UTC (rev 85314)
@@ -49,7 +49,8 @@
        {
                DataSourceSelectArguments selectArguments;
                DataSourceView currentView;
-
+               bool preLoadDone;
+               
                protected DataBoundControl ()
                {
                }
@@ -121,20 +122,24 @@
                        base.OnPagePreLoad (sender, e);
 
                        Initialize ();
+                       preLoadDone = true;
                }
 
                private void Initialize ()
                {
-                       if (!Page.IsPostBack || (IsViewStateEnabled && 
!IsDataBound))
-                               RequiresDataBinding = true;
-
+                       Page page = Page;
+                       
+                       if (((page != null) && !preLoadDone) && !IsDataBound)
+                               if (!page.IsPostBack)
+                                       RequiresDataBinding = true;
                        UpdateViewData ();
                }
                
                void UpdateViewData ()
                {
                        DataSourceView view = InternalGetData ();
-                       if (view == currentView) return;
+                       if (view == currentView)
+                               return;
 
                        if (currentView != null)
                                currentView.DataSourceViewChanged -= new 
EventHandler (OnDataSourceViewChanged);
@@ -147,14 +152,8 @@
                
                protected internal override void OnLoad (EventArgs e)
                {
-                       if (!Initialized) {
-                               
-                               Initialize ();
-
-                               // MSDN: The ConfirmInitState method sets the 
initialized state of the data-bound 
-                               // control. The method is called by the 
DataBoundControl class in its OnLoad method.
-                               ConfirmInitState ();
-                       }
+                       ConfirmInitState ();
+                       Initialize ();
                        base.OnLoad(e);
                }
                
@@ -197,13 +196,16 @@
                        if (!IsBoundUsingDataSourceID)
                                OnDataBinding (EventArgs.Empty);
 
+                       DataSourceView data = GetData ();
+                       
                        // prevent recursive calls
+                       
+                       SelectArguments = CreateDataSourceSelectArguments ();
                        RequiresDataBinding = false;
-                       SelectArguments = CreateDataSourceSelectArguments ();
-                       GetData ().Select (SelectArguments, new 
DataSourceViewSelectCallback (OnSelect));
 
                        // The PerformDataBinding method has completed.
                        MarkAsDataBound ();
+                       data.Select (SelectArguments, new 
DataSourceViewSelectCallback (OnSelect));
                        
                        // Raise the DataBound event.
                        OnDataBound (EventArgs.Empty);

Modified: trunk/mcs/class/System.Web/System.Web.UI.WebControls/ListControl.cs
===================================================================
--- trunk/mcs/class/System.Web/System.Web.UI.WebControls/ListControl.cs 
2007-09-04 18:07:21 UTC (rev 85313)
+++ trunk/mcs/class/System.Web/System.Web.UI.WebControls/ListControl.cs 
2007-09-04 18:48:11 UTC (rev 85314)
@@ -61,8 +61,6 @@
 
                private ListItemCollection items;
 #if NET_2_0
-               bool dataAlreadyBound;
-               
                int _selectedIndex = -2;
                string _selectedValue;
 #else          
@@ -86,6 +84,8 @@
                        }
                        set {
                                ViewState ["AppendDataBoundItems"] = value;
+                               if (Initialized)
+                                       RequiresDataBinding = true;
                        }
                }
 #endif         
@@ -137,7 +137,13 @@
                [WebCategory ("Data")]
                public virtual string DataTextField {
                        get { return ViewState.GetString ("DataTextField", 
String.Empty); }
-                       set { ViewState ["DataTextField"] = value; }
+                       set { 
+                               ViewState ["DataTextField"] = value;
+#if NET_2_0
+                               if (Initialized)
+                                       RequiresDataBinding = true;
+#endif
+                       }
                }
 
 #if NET_2_0
@@ -148,7 +154,13 @@
                [WebCategory ("Data")]
                public virtual string DataTextFormatString {
                        get { return ViewState.GetString 
("DataTextFormatString", String.Empty); }
-                       set { ViewState ["DataTextFormatString"] = value; }
+                       set { 
+                               ViewState ["DataTextFormatString"] = value;
+#if NET_2_0
+                               if (Initialized)
+                                       RequiresDataBinding = true;
+#endif
+                       }
                }
 
 #if NET_2_0
@@ -159,7 +171,13 @@
                [WebCategory ("Data")]
                public virtual string DataValueField {
                        get { return ViewState.GetString ("DataValueField", 
String.Empty); }
-                       set { ViewState ["DataValueField"] = value; }
+                       set { 
+                               ViewState ["DataValueField"] = value;
+#if NET_2_0
+                               if (Initialized)
+                                       RequiresDataBinding = true;
+#endif
+                       }
                }
 
 #if NET_2_0
@@ -413,10 +431,7 @@
                        if (dataSource == null)
                                return;
 #if NET_2_0
-                       if (AppendDataBoundItems) {
-                               if (dataAlreadyBound)
-                                       return;
-                       } else
+                       if (!AppendDataBoundItems)
 #endif
                                Items.Clear ();
 
@@ -455,7 +470,6 @@
                        }                       
 
 #if NET_2_0
-                       dataAlreadyBound = true;
                        if (!String.IsNullOrEmpty (_selectedValue)) {
                                if (!SetSelectedValue (_selectedValue))
                                        throw new ArgumentOutOfRangeException 
("value", String.Format ("'{0}' has a SelectedValue which is invalid because it 
does not exist in the list of items.", ID));

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to