Inserted into a Web page as a placeholder when the attempt to load or create a new instance of a dynamic WebPart control has failed.
Assembly: System.Web (in System.Web.dll)
[AspNetHostingPermissionAttribute(SecurityAction.InheritanceDemand, Level = AspNetHostingPermissionLevel.Minimal)] [AspNetHostingPermissionAttribute(SecurityAction.LinkDemand, Level = AspNetHostingPermissionLevel.Minimal)] public class ErrorWebPart : ProxyWebPart, ITrackingPersonalizable
The class is used by the Web Parts control set as a placeholder for a WebPart control that could not be added to the page. If the WebPartManager control attempts to load or create a new instance of a dynamic WebPart control in a zone, and the attempt fails for some reason, the WebPartManager then calls the CreateErrorWebPart method, and inserts an control in place of the control that failed.
The control is inserted to preserve previously existing personalization state information that might have existed on a control for users. For example, suppose there is a WebPart control that has a personalizable property, so that users can save their own ZIP Code, and then the control can automatically display weather information for that ZIP Code each time the user visits the page. If at some point a problem occurs with the weather control so that it cannot be loaded during a specific request, and yet the rest of the page does load successfully, the custom personalization data that a user has saved for that control would be lost the next time the personalization data for the page is saved. By inserting the control in place of the failed control, you can notify the user that a problem has occurred, and also provide a mechanism for the Web Parts control set to preserve the user's personalization data on the failed control until the problem can be corrected.
The class derives from the ProxyWebPart class, as one of several types designed to be temporary placeholders for other types. To create an instance of the class, the WebPartManager control uses its public ErrorWebPart constructor. The constructor requires several details of the failed control to be passed to it, such as the ID, the original type of the control (if the failed control is a server or user control wrapped in a GenericWebPart object), the original path to the source file for the control (if the failed control is a user control), and the ID of a GenericWebPart object if present.
The class has a single public property called ErrorMessage. Developers can assign a value to this property that will be displayed in a Web page when the control is inserted.
The class has three protected methods. The AddAttributesToRender method takes style characteristics from the ErrorStyle object for the WebZone zone that contains the control that failed to load. If any style settings exist in this object, the method applies them to the control. The EndLoadPersonalization method sets several important inherited properties on the control, to prevent users from personalizing the control by hiding, minimizing, editing, or exporting it, or changing its ChromeState value. Finally, the RenderContents method encodes the value of the string in the ErrorMessage property, to prevent rendering problems or scripting attacks.Notes to Inheritors:
The conditions in which an control is actually inserted into a page are relatively rare, and although the class can be inherited from and extended, few developers will find this to be of great importance. One reason you might want to extend this class is if you want to customize the appearance and behavior of the control. For example, you could override the EndLoadPersonalization method, and set additional style or other properties on the control, beyond those that are already set.
To require the WebPartManager control to use a custom control, you must also inherit from the WebPartManager class and override its CreateErrorWebPart method. In that method, you should assign the value of the method's errorMessage parameter to the ErrorMessage property of your custom control, because the WebPartManager control calls this method from several other places, and often passes in a different error message value.
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.