public void Deny_Unrestricted () { // note: using the same control (as owner) to add results // in killing the ms runtime with a stackoverflow - FDBK36722 ControlCollection cc = new ControlCollection (new Control ()); Assert.AreEqual (0, cc.Count, "Count"); Assert.IsFalse (cc.IsReadOnly, "IsReadOnly"); Assert.IsFalse (cc.IsSynchronized, "IsSynchronized"); Assert.IsNotNull (cc.SyncRoot, "SyncRoot"); cc.Add (control); Assert.IsNotNull (cc[0], "this[int]"); cc.Clear (); cc.AddAt (0, control); Assert.IsTrue (cc.Contains (control), "Contains"); cc.CopyTo (new Control[1], 0); Assert.IsNotNull (cc.GetEnumerator (), "GetEnumerator"); Assert.AreEqual (0, cc.IndexOf (control), "IndexOf"); cc.RemoveAt (0); cc.Remove (control); }
static public void RemoveProblemTypes(ControlCollection coll, List<ControlRestorationInfo> stashedControls) { foreach (Control ctrl in coll) { if (typeof(RequiredFieldValidator).IsAssignableFrom(ctrl.GetType()) || typeof(CompareValidator).IsAssignableFrom(ctrl.GetType()) || typeof(RegularExpressionValidator).IsAssignableFrom(ctrl.GetType()) || typeof(ValidationSummary).IsAssignableFrom(ctrl.GetType())) { ControlRestorationInfo cri = new ControlRestorationInfo(ctrl, coll); stashedControls.Add(cri); coll.Remove(ctrl); continue; } if (ctrl.HasControls()) { RemoveProblemTypes(ctrl.Controls, stashedControls); } } }
/// <summary> /// Moves all templated controls of a given region provider /// into their target regions. /// </summary> /// <param name="template">The template to be used.</param> /// <param name="controls">Controls to move into the template.</param> /// <param name="provider">Provides region assignements for the controls.</param> /// <param name="page">The currently rendered page.</param> protected static void HandleControls(IPortalTemplate template, RegionProvider provider, ControlCollection controls, Page page) { //force template control creation now by adding / removing the template Control templateControl = (Control)template; controls.Add(templateControl); controls.Remove(templateControl); //call initialization code of the template template.BeforeTemplating(page); //add defined controls to their target region RegionPlaceHolder placeHolder; foreach (RegionPropertySet propertySet in provider) { placeHolder = template[propertySet.TargetRegion]; if (placeHolder == null) { string msg = "Invalid region defined for control {0}. Template does not contain region '{1}'"; msg = String.Format(msg, propertySet.Control.ID, propertySet.TargetRegion); throw new ArgumentException(msg); } //remove templated control from original location... controls.Remove(propertySet.Control); //...and put it into placeholder placeHolder.Controls.Add(propertySet.Control); } //add remaining controls to default region, if any if (provider.DefaultRegion != PortalRegion.None) { placeHolder = template[provider.DefaultRegion]; if (placeHolder == null) { string msg = "Invalid default region defined: Template does not contain region '{0}'"; msg = String.Format(msg, provider.DefaultRegion); throw new ArgumentException(msg); } //move remaining controls into the template's controls ControlUtil.MoveControls(controls, placeHolder.Controls); } //Everything is now in the template. Now move all the template's //controls back into the page's control collection. This is necessary //to keep relative links of the web form working ControlUtil.MoveControls(templateControl.Controls, controls); //call initialization code of the template template.AfterTemplating(page); }