views:

1505

answers:

2

I am trying to dynamically adjust the width and height of a web part in a SharePoint web part page so that it fills up the entire available space. It appears that there is no way to choose a percentage for width and height from the web part property editor window in SharePoint. Also, trying to dynamically set it on the web part instance through code results in SharePoint throwing an exception to the effect that proportional dimensions are not supported.

Is there any way to do this using, for example, Javascript? I've seen similar things done using jQuery, but not exactly what I'm looking for (and I'm not familiar enough with jQuery to come up with something on my own).

A: 

There is a web part available that does this here. You can also see a solution on TechNet communities from "potta vijay kumar" (where I found that web part too):

function calcHeight() 
{ 
  //find the height of the internal page 
    var the_height= 
    document.getElementById('contentpage').contentWindow. 
      document.body.scrollHeight; 

  //change the height of the iframe 
  document.getElementById('contentpage').height= 
      the_height; 
}

contentpage is the ID of the iframe.

A jQuery solution is available from EndUserSharePoint.

Alex Angas
A: 

Do I understand that you wish to set the size of a web part? Why not set the width in the UI properties dialog through the browser?

Wartickler
I want to set the size dynamically, so that as the page grows/shrinks, so does the web part. The UI properties only allow you to set fixed width and height values.