WebPart Constructor ()
Initializes the class for use by an inherited class instance. This constructor can only be called by an inherited class.
Assembly: System.Web (in System.Web.dll)
The WebPart constructor initializes default values for several UI-oriented properties, including the various Allow properties that determine the control's capabilities. These properties are then incorporated into an inherited class instance.
The following code example demonstrates how a control that derives from the WebPart class inherits the default property values set in the base WebPart constructor, but then changes the value of one property in the constructor of the derived control.
The first part of this example contains the code for a custom WebPart control named TextDisplayWebPart. This control demonstrates how to create a simple custom WebPart control that gives you access to the features of the Web Parts control set. Note that in the constructor of the custom control, the TextDisplayWebPart.AllowClose property is set to false, which has the effect of preventing users from closing the control on a Web page. For the code example to run, you must compile this source code. You can compile it explicitly and put the resulting assembly in your Web site's Bin folder or the global assembly cache. Alternatively, you can put the source code in your site's App_Code folder, where it will be dynamically compiled at run time. This code example assumes that you compile the source code into an assembly, place it in a Bin subfolder of your Web application, and reference the assembly with a Register directive in your Web page. For a walkthrough that demonstrates both methods of compiling, see Walkthrough: Developing and Using a Custom Web Server Control.
The second part of the example shows how to reference the TextDisplayWebPart control in an ASP.NET Web page. After you load the page in a browser, if you click the verbs menu in the title bar of the custom WebPart control, the close verb is now disabled, which prevents users from closing the control.
Available since 2.0