Fredrik Normén's Blog - NSQUARED²
Any fool can write code that a computer can understand. Good programmers write code that humans can understand.

Microsoft Most Valuable Professional
     .Net Framework - ASP.Net - Architecture - Development
NOTE: This list of posts will only list the 15 latest posts, to see the rest, select from the Archives located in the menu to the left. The RSS will only list the 10 lastest posts.
GenericWebParts

Category:  ASP.Net 2.0

When a control is added to the WebPartZone’s controls collection and the control didn’t inherit the WebPart class it will be turned into a GenericWebPart (A GenereicWebPart’s inherits the WebPart class so it inherits all the WebParts behavior). The control will be the child control of the GenericWebPart.

 

When a WebPart is rendered by the WebPartZone, the zone will call some certain WebPart properties, such as Title, Description, Height, Width etc. The different between a regular WebPart and a GenericWebpart is that when a GenereicWebpart’s WebPart specific property is called, the GenericWebPart will look for an attribute of the same name as the property in the attributes collection of its ChildControl. This allows us to set certain WebPart properties on our ChildControl, even though our child control does not contain these properties. For example:

 

<asp:WebPartZone id="webPartZone1" runat=server>

  <ZoneTemplate>

    <ctl:MyControl title="My Control Title" description="My Control Description" id="myControl1" runat="server" />

  </ZoneTemplate>

</asp:WebPartZone>


This code will cause the Title property of the GenericWebPart to return "My Control Title" and the Description property to return "My Control Description".

The following is a list of properties that GenericWebPart handles this way. Some of them exist in the May CTP and some will be available in Beta 2, such as the AuthorizationFilter and ExportMode:


AuthorizationFilter (Beta 2)
CatalogIconImageUrl
Description
ExportMode (Beta 2)
Height
Subtitle
Title
TitleIconImageUrl
TitleUrl
Width

 

In beta 2 we could set the AuthorizationFilter on a control added to the WebPartZone, this will not be possible in beta 1 if the control doesn’t inherit the WebPart class.

Posted: Wednesday, June 23, 2004 - 17:25 GMT+1    Print     E-mail    Comments (2)
   fredrik.nsquared2.com - 2007