1

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!

0

1 Answer 1

3

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);
    ...
}
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.