Thursday, March 12, 2009

The operation could not be completed because the Web Part is not on this page

Error:


The operation could not be completed because the Web Part is not on this page.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.


Exception Details: Microsoft.SharePoint.WebPartPages.WebPartPageUserException: The operation could not be completed because the Web Part is not on this page.


Source Error:


An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.


Stack Trace:

[WebPartPageUserException: The operation could not be completed because the Web Part is not on this page.]
Microsoft.SharePoint.WebPartPages.SPWebPartManager.ThrowIfNotOnPage(WebPart webPart) +128
Microsoft.SharePoint.WebPartPages.SPWebPartManager.GetStorageKey(WebPart webPart) +36
Microsoft.SharePoint.WebControls.ViewIcon.get_Src() +172
Microsoft.SharePoint.WebControls.AlphaImage.Render(HtmlTextWriter output) +57
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +199
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20
System.Web.UI.Control.Render(HtmlTextWriter writer) +7
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +199
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20
System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer) +59
System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter output) +68
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer) +37
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +199
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20
System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer) +29
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +199
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20
System.Web.UI.Control.Render(HtmlTextWriter writer) +7
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +199
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +20
System.Web.UI.Page.Render(HtmlTextWriter writer) +26
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +25
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +121
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +22
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2558


Cause by:

Web parts added declaratively (in the asp code) in a list's view (AllItems.aspx, Flat.apx, Threaded.aspx) or form (NewForm.aspx, DispForm.aspx or EditForm.aspx) which contains a SharePoint:ViewIcon control (responsible of drawing the list's image in the upper left corner of the page):




Example:




Solution:
1) Remove the SharePoint:ViewIcon from the page
or
2) Use C# code to inject the web parts in the page:
Example:
SPWeb web = SPContext.Current.Web;
SPLimitedWebPartManager wpManager = web.GetLimitedWebPartManager(web.Lists[listId].DefaultViewUrl, PersonalizationScope.Shared);
MyWebPart myWP = new MyWebPart();
myWP.ChromeType = PartChromeType.TitleAndBorder;
myWP.Title = "My Web Part";
wpManager.AddWebPart(myWP, "WebPartZone1", 0);

1 comment:

Anonymous said...

Thank you so much, your blog helped me save a lot of time