I have an application that is allowing users to Add, Edit, and Delete WebParts (which are User Controls) from one page with two WebPartZones. It seems to work except when there is only one WebPart left on the page and you try to Delete it. It appears to delete in Edit mode (plus, WebPartManager.WebParts.Count=0) but then when you hit Finish and go back to Browse mode, the WebPart is still there. Through debugging I was able to determine that SavePersonalizationBlob() from our PersonalizationProvider (inheriting SQLPersonalizationProvider) is not called after the Delete on the last WebPart like it is on the other deletes. So as it returns to Browse mode, it loads the blob saved before the delete. This seems like a bug to me, or maybe I'm just misunderstanding how this works.
I thought I could work around this by forcing a save on finish of editting, but it seems to be impossible. I developed my own WebPartManager class and tried to use SetPersonalizationDirty() but I think that just sets a flag and doesn't actually fire the event to save. If I exit the app and come back with this change, the WebPart is actually gone. So that's something, but not an acceptable long term solution. Without the SetPersonalizationDirty() call, the WebPart is still there when I open it up again.
Any ideas? I have been unable to find anyone else having this trouble.