Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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!

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

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);
    ...
}
share|improve this answer
    
Great! Thanks for posting the answer. –  Kit Menke Aug 8 '11 at 15:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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