I have been looking for any leads on this direction on the web and most of the issues I have found is when they try to add a webpart but I am running across the issue where I am getting an exception when trying to remove it. I have no trouble adding it and the web part does work once added to e webpartpage. I tried removing it and it throws an exception. I am a bit confused because my next step was to remove the code on CreateChildControls() and once I did that there was not issue with removing the web part. So its related specifically to my web part I believe. I am not quite sure what fires when a web part is deleted (related to my web parts). Just starting with all this so take it easy :)
This is what I get when I try to delete the web part:
Server Error in '/' Application.
Microsoft.SharePoint.WebPartPages.WebPartPageUserException at Microsoft.SharePoint.WebPartPages.SPWebPartManager.OnWebPartDeleting>(WebPartCancelEventArgs eventArgs) at System.Web.UI.WebControls.WebParts.WebPartManager.CloseOrDeleteWebPart(WebPart webPart, Boolean delete) at Microsoft.SharePoint.WebPartPages.SPWebPartManager.DeleteWebPartInternal(WebPart webPart) at Microsoft.SharePoint.SPWebPartCollection.Delete(Guid storageKey) at Microsoft.SharePoint.WebPartPages.WebPart.DeleteMenuOptionClick(WebPart part, Object sender, EventArgs eventArgs) at Microsoft.SharePoint.WebPartPages.MenuItem.Click(Object sender, EventArgs e) at Microsoft.SharePoint.WebPartPages.SPWebPartManager.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
private const string _ascxPath = @"~/_CONTROLTEMPLATES/[ControlLocation]";
protected override void CreateChildControls()
{
try
{
Control control = Page.LoadControl(_ascxPath);
Controls.Add(control);
}
catch (Exception ex)
{
Controls.Clear();
LiteralControl control = new LiteralControl(ex.ToString());
Controls.Add(control);
}
}