I know how to make custom properties for web parts in SharePoint, but is there a way to override the ones that are already generated? For example I have a Page Viewer embedded within my custom web part, and I would like to override the default "Height" property that the user can type a value for in the property window so that I can pass it to the height of my Page Viewer. That way the page viewer stretched to the appropriate height instead of my web part stretching, but not the page viewer. Any help is appreciated, thanks!
1 Answer
Just call this.Height, this.Title, this.Width (whichever default property) etc... and set them within CreateChildControls() to override what the user typed.
Example:
protected override void CreateChildControls()
{
...
this.Title = "Foo";
this.Height = 500;
...
}
However, this just updates the whole web part. In my question, I have an embedded PageViewerWebPart, so I would need code like this to actually get the page viewer to stretch to the size of my custom web part containing it:
protected override void CreateChildControls()
{
...
PageViewerWebPart pvwp = new PageViewerWebPart();
pvwp.ContentLink = "http://www.google.com"
pvwp.Height = this.Height;
this.Controls.Add(pvwp);
...
}