A seemingly simple question, but I haven't found the answer online. I have developed a web part with an adjustable height/width. After adding the web part to my web part page, I open the configuration panel. The properties of the web part under Appearance: "Should the Web Part have a fixed width?" defaults to "No. Adjust width to fit zone." The web part can then be set to a custom width by selecting "Yes" and setting the width.
All good so far. The web parts resize quite well unless you make them exceedingly skinny or wide. I would like to set my web part a minimum width of 250px, and a maximum of 1000px. How can I do this?
These parts are going to be added to hundreds of pages. Thus to minimise the amount of configuration necessary, I would also like the web part to default to having a fixed width of 400px, which is the size they look the best for most purposes. However, I'd still like the user to be able to change the configuration to "No. Adjust height to fit zone." or customise the width if it is too narrow for their purpose.
Setting the size of the panel to 400px works, but then the part cannot be customised.
I have tried adding the following property to the .webpart file:
<property name="Width" type="string">400px</property>
I have also tried overriding the width attribute and setting a _width field to a default of 400px.
public string _width;
[PersonalizableAttribute]
[WebPartStorageAttribute(Storage = Storage.Personal)]
public string Width
{
get
{
if (_width == null || _width == string.Empty) { _width = "400px"; }
return _width;
}
set { _width = value; }
}
I've also tried it like this:
public System.Web.UI.WebControls.Unit _width;
[PersonalizableAttribute]
[WebPartStorageAttribute(Storage = Storage.Personal)]
public override System.Web.UI.WebControls.Unit Width
{
get
{
if (_width == null) { _width = new System.Web.UI.WebControls.Unit("400px"); }
return _width;
}
set { _width = value; }
}
but none of these appear to have any effect whatsoever.