So you have your web part and you want to pre-configure the height of the web part at time of deployment, rather than have the support department have to set the height everywhere your part has automatically been added etc.

I found this Gem on how to create preconfigured custom properrties here
http://weblogs.asp.net/mnissen/archive/2004/05/20/135744.aspx
and just adpated it for Base properties (with a slight bodge), there may be a better way but I don’t have time to find it (I did try overriding/new the Height property but it wouldn’t have it).

In your web part code create a custom property for DefaultHeight in your class e.g.

[DefaultProperty(“TeamName”),ToolboxData(“”),
XmlRoot(Namespace=http://www.BinaryJam.com/HelpDeskWebParts/TeamWebPart)]
public class TeamWebPart : Microsoft.SharePoint.WebPartPages.WebPart
{
[Browsable(false),DefaultValue(defaultText),WebPartStorage(Storage.Shared)]
public string DefaultHeight{
get {
return this.Height;
}
set {
this.Height = value;
}
}
}

Then using the techniques described in the blog entry, enter the following line in the DWP file.

DefaultHeight xmlns=”http://EonUK/Oberon/RemedyWebPart/TeamWebPart”>150DefaultHeight>

When deployed this has the effect of Setting the Height of the Part to 150 pixels.

This technique could be used for width or any of the base properties exposed by WebPart.

Advertisements