Export (0) Print
Expand All

ErrorWebPart Class

Note: This class is new in the .NET Framework version 2.0.

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.

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

public class ErrorWebPart : ProxyWebPart, ITrackingPersonalizable
public class ErrorWebPart extends ProxyWebPart implements ITrackingPersonalizable
public class ErrorWebPart extends ProxyWebPart implements ITrackingPersonalizable

The ErrorWebPart 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 ErrorWebPart control in place of the control that failed.

The ErrorWebPart 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 ErrorWebPart 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 ErrorWebPart 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 ErrorWebPart 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 ErrorWebPart 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 ErrorWebPart control. The EndLoadPersonalization method sets several important inherited properties on the ErrorWebPart 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 ErrorWebPart 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 ErrorWebPart control. For example, you could override the EndLoadPersonalization method, and set additional style or other properties on the ErrorWebPart control, beyond those that are already set. To require the WebPartManager control to use a custom ErrorWebPart 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 ErrorWebPart control, because the WebPartManager control calls this method from several other places, and often passes in a different error message value.

System.Object
   System.Web.UI.Control
     System.Web.UI.WebControls.WebControl
       System.Web.UI.WebControls.Panel
         System.Web.UI.WebControls.WebParts.Part
           System.Web.UI.WebControls.WebParts.WebPart
             System.Web.UI.WebControls.WebParts.ProxyWebPart
              System.Web.UI.WebControls.WebParts.ErrorWebPart

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft