WebPartManager.CreateErrorWebPart Method (String, String, String, String, String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Creates a special control that is inserted into a page and displayed for end users, when an attempt to load or create a dynamic WebPart control fails for some reason.

Namespace:   System.Web.UI.WebControls.WebParts
Assembly:  System.Web (in System.Web.dll)

protected virtual ErrorWebPart CreateErrorWebPart(
	string originalID,
	string originalTypeName,
	string originalPath,
	string genericWebPartID,
	string errorMessage


Type: System.String

A string that is the ID of the failing control. If a GenericWebPart is involved in the failure, the ID is the ID of its child server control.

Type: System.String

A string that is the name of the Type of the failed control. If a GenericWebPart is involved in the failure, the type name is the type of its child server control.

Type: System.String

A string that contains the path to a user control, if a GenericWebPart that contains a child user control is involved in the failure.

Type: System.String

A string that returns the ID of a GenericWebPart, if that type of control was involved in the failure to load or create a control.

Type: System.String

A string that contains the error message to display on the page.

Return Value

Type: System.Web.UI.WebControls.WebParts.ErrorWebPart

An ErrorWebPart that is inserted into a page in place of a control that failed to be loaded or created.

The CreateErrorWebPart method is called when the Web Parts control set attempts to load or create an instance of a dynamic WebPart or server control, and it fails for some reason. The method creates an ErrorWebPart object, assigns an error message to it, and returns it. The ErrorWebPart control is inserted in place of the control that failed, and its error message is displayed on the page.

You cannot call the CreateErrorWebPart method directly from your code. However, you can inherit from the WebPartManager class and extend the method. For details, see the Notes for Inheritors section.

End users can work with an ErrorWebPart control in a page much like they would a normal WebPart control. To remove the error message, they can close the control by clicking the close verb, at which point the control will be added to a PageCatalogPart object, like any other closed control. If an end user deletes an ErrorWebPart control, the server control that failed to load will also be deleted from the page.

Notes to Inheritors:

If you want to customize the information that is returned in the ErrorWebPart control, you can override the CreateErrorWebPart method, call the base method, assign different values to the parameters passed to the base method, and then return the resulting ErrorWebPart control. For example, if you do not want end users to see the originalPath value (which would show the virtual directory path of a user control), when you call the base method you could pass an empty string ("") for that parameter.

You can also customize the behavior of the ErrorWebPart control itself, by inheriting from it. For example, you might want to override its Title or AllowMinimize property.

.NET Framework
Available since 2.0
Return to top