2009-10-30 Marek Habersack <mhabersack@novell.com>
[mono.git] / mcs / class / System.Web / System.Web.UI.WebControls / MultiView.cs
index d7eb70359f9589657e8d31f69922780978422e49..444fe1ac011b76dcbbbc03e9ce2bc04dd6c62d77 100644 (file)
@@ -41,7 +41,11 @@ namespace System.Web.UI.WebControls
 //     [ControlBuilder (typeof(MultiViewControlBuilder)]
        [Designer ("System.Web.UI.Design.WebControls.MultiViewDesigner, " + Consts.AssemblySystem_Design, "System.ComponentModel.Design.IDesigner")]
        [ToolboxData ("<{0}:MultiView runat=\"server\"></{0}:MultiView>")]
-       [ParseChildren (false, ChildControlType = typeof(View))]
+#if NET_2_0
+       [ParseChildren (typeof(View))]
+#else
+       [ParseChildren (false)]
+#endif
        [DefaultEvent ("ActiveViewChanged")]
        public class MultiView: Control
        {
@@ -50,11 +54,10 @@ namespace System.Web.UI.WebControls
                public static readonly string SwitchViewByIDCommandName = "SwitchViewByID";
                public static readonly string SwitchViewByIndexCommandName = "SwitchViewByIndex";
                
-               private static readonly object ActiveViewChangedEvent = new object();
+               static readonly object ActiveViewChangedEvent = new object();
                
                int viewIndex = -1;
                int initialIndex = -1;
-               bool initied = false;
                
                public event EventHandler ActiveViewChanged {
                        add { Events.AddHandler (ActiveViewChangedEvent, value); }
@@ -65,8 +68,10 @@ namespace System.Web.UI.WebControls
                {
                        if (ob is View)
                                Controls.Add (ob as View);
-                       else
-                               throw new HttpException ("MultiView cannot have children of type 'Control'.  It can only have children of type 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 ()
@@ -94,14 +99,14 @@ namespace System.Web.UI.WebControls
                public virtual int ActiveViewIndex {
                        get
                        {
-                               if (!initied)
+                               if (Controls.Count == 0)
                                        return initialIndex;
 
                                return viewIndex;
                        }
                        set 
                        {
-                               if (!initied) {
+                               if (Controls.Count == 0) {
                                        initialIndex = value;
                                        return;
                                }
@@ -118,19 +123,16 @@ namespace System.Web.UI.WebControls
                                        ((View)Controls [viewIndex]).NotifyActivation (true);
 
                                UpdateViewVisibility ();
+
+                               OnActiveViewChanged (EventArgs.Empty);
                        }
                }
 
                [Browsable (true)]
-               [MonoTODO]
                public virtual new bool EnableTheming
                {
-                       get {
-                               throw new NotImplementedException ();
-                       }
-                       set {
-                               throw new NotImplementedException ();
-                       }
+                       get { return base.EnableTheming; }
+                       set { base.EnableTheming = value; }
                }
                
                [PersistenceMode (PersistenceMode.InnerDefaultProperty)]
@@ -173,7 +175,6 @@ namespace System.Web.UI.WebControls
                
                protected internal override void OnInit (EventArgs e)
                {
-                       initied = true;
                        Page.RegisterRequiresControlState (this);
                        if (initialIndex != -1) {
                                ActiveViewIndex = initialIndex;
@@ -223,7 +224,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);
                }