oops
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / MultiView.cs
index f2ea72e0243beee6c048b7479fd04676d0186699..f0a74151c1ee0508d7e1c42d43e0e3452f25cccf 100644 (file)
@@ -54,7 +54,6 @@ namespace System.Web.UI.WebControls
                
                int viewIndex = -1;
                int initialIndex = -1;
-               bool initied;
                
                public event EventHandler ActiveViewChanged {
                        add { Events.AddHandler (ActiveViewChangedEvent, value); }
@@ -65,6 +64,10 @@ namespace System.Web.UI.WebControls
                {
                        if (ob is View)
                                Controls.Add (ob as View);
+                       // LAMESPEC: msdn talks that only View contorls are allowed, for others controls HttpException should be thrown
+                       // but actually, aspx praser adds LiteralControl controls.
+                       //else
+                       //      throw new HttpException ("MultiView cannot have children of type 'Control'.  It can only have children of type View.");
                }
                
                protected override ControlCollection CreateControlCollection ()
@@ -90,9 +93,16 @@ namespace System.Web.UI.WebControls
                
                [DefaultValue (-1)]
                public virtual int ActiveViewIndex {
-                       get { return viewIndex; }
-                       set {
-                               if (!initied) {
+                       get
+                       {
+                               if (Controls.Count == 0)
+                                       return initialIndex;
+
+                               return viewIndex;
+                       }
+                       set 
+                       {
+                               if (Controls.Count == 0) {
                                        initialIndex = value;
                                        return;
                                }
@@ -164,7 +174,6 @@ namespace System.Web.UI.WebControls
                
                protected internal override void OnInit (EventArgs e)
                {
-                       initied = true;
                        Page.RegisterRequiresControlState (this);
                        if (initialIndex != -1) {
                                ActiveViewIndex = initialIndex;
@@ -176,7 +185,7 @@ namespace System.Web.UI.WebControls
                void UpdateViewVisibility ()
                {
                        for (int n=0; n<Views.Count; n++)
-                               Views [n].Visible = (n == viewIndex);
+                               Views [n].VisibleInternal = (n == viewIndex);
                }
                
                protected internal override void RemovedControl (Control ctl)
@@ -214,7 +223,8 @@ namespace System.Web.UI.WebControls
                
                protected internal override void Render (HtmlTextWriter writer)
                {
-                       if (!initied) viewIndex = initialIndex;
+                       if ((Controls.Count == 0) && (initialIndex != -1)) 
+                               viewIndex = initialIndex;
                        if (viewIndex != -1)
                                GetActiveView ().Render (writer);
                }