internal void RemoveWebPart(WebPart webPart)
 {
     string errorMsg = base.SetCollectionReadOnly(null);
     try
     {
         try
         {
             this._manager._partAndChildControlIDs.Remove(webPart.ID);
             GenericWebPart part = webPart as GenericWebPart;
             if (part != null)
             {
                 this._manager._partAndChildControlIDs.Remove(part.ChildControl.ID);
             }
             this.Remove(webPart);
             this._manager._hasDataChanged = true;
             webPart.SetWebPartManager(null);
             this._manager.Internals.SetIsStandalone(webPart, true);
             this._manager._partsForZone = null;
         }
         finally
         {
             base.SetCollectionReadOnly(errorMsg);
         }
     }
     catch
     {
         throw;
     }
 }
            internal void RemoveWebPart(WebPart webPart) {
                string originalError = SetCollectionReadOnly(null);
                // Extra try-catch block to prevent elevation of privilege attack via exception filter
                try {
                    try {
                        _manager._partAndChildControlIDs.Remove(webPart.ID);

                        // Remove child control ID (VSWhidbey 339482)
                        GenericWebPart genericWebPart = webPart as GenericWebPart;
                        if (genericWebPart != null) {
                            _manager._partAndChildControlIDs.Remove(genericWebPart.ChildControl.ID);
                        }

                        Remove(webPart);
                        _manager._hasDataChanged = true;
                        webPart.SetWebPartManager(null);
                        _manager.Internals.SetIsStandalone(webPart, true);

                        // Invalidate the part dictionary if it has already been created
                        _manager._partsForZone = null;
                    }
                    finally {
                        SetCollectionReadOnly(originalError);
                    }
                }
                catch {
                    throw;
                }
            }
 private void AddWebPartHelper(WebPart webPart)
 {
     string iD = webPart.ID;
     if (string.IsNullOrEmpty(iD))
     {
         throw new InvalidOperationException(System.Web.SR.GetString("WebPartManager_NoWebPartID"));
     }
     if (this._manager._partAndChildControlIDs.Contains(iD))
     {
         throw new InvalidOperationException(System.Web.SR.GetString("WebPartManager_DuplicateWebPartID", new object[] { iD }));
     }
     this._manager._partAndChildControlIDs.Add(iD, null);
     GenericWebPart part = webPart as GenericWebPart;
     if (part != null)
     {
         string str2 = part.ChildControl.ID;
         if (string.IsNullOrEmpty(str2))
         {
             throw new InvalidOperationException(System.Web.SR.GetString("WebPartManager_NoChildControlID"));
         }
         if (this._manager._partAndChildControlIDs.Contains(str2))
         {
             throw new InvalidOperationException(System.Web.SR.GetString("WebPartManager_DuplicateWebPartID", new object[] { str2 }));
         }
         this._manager._partAndChildControlIDs.Add(str2, null);
     }
     this._manager.Internals.SetIsStandalone(webPart, false);
     webPart.SetWebPartManager(this._manager);
     this.Add(webPart);
     this._manager._partsForZone = null;
 }
            private void AddWebPartHelper(WebPart webPart) {
                string partID = webPart.ID;
                if (String.IsNullOrEmpty(partID)) {
                    throw new InvalidOperationException(SR.GetString(SR.WebPartManager_NoWebPartID));
                }
                if (_manager._partAndChildControlIDs.Contains(partID)) {
                   throw new InvalidOperationException(SR.GetString(SR.WebPartManager_DuplicateWebPartID, partID));
                }

                // Add to dictionary to prevent duplicate IDs, even if this part is not authorized.  Don't want page
                // developer to have 2 parts with the same ID, and not get the exception until they are both authorized.
                _manager._partAndChildControlIDs.Add(partID, null);

                // Check and add child control ID (VSWhidbey 339482)
                GenericWebPart genericWebPart = webPart as GenericWebPart;
                if (genericWebPart != null) {
                    string childControlID = genericWebPart.ChildControl.ID;

                    if (String.IsNullOrEmpty(childControlID)) {
                        throw new InvalidOperationException(SR.GetString(SR.WebPartManager_NoChildControlID));
                    }

                    if (_manager._partAndChildControlIDs.Contains(childControlID)) {
                        throw new InvalidOperationException(SR.GetString(SR.WebPartManager_DuplicateWebPartID, childControlID));
                    }

                    _manager._partAndChildControlIDs.Add(childControlID, null);
                }

                _manager.Internals.SetIsStandalone(webPart, false);
                webPart.SetWebPartManager(_manager);
                Add(webPart);

                // Invalidate the part dictionary if it has already been created
                _manager._partsForZone = null;
            }