By default when you edit the tool part settings of a SharePoint web part and you click on the ‘…’ if the property is a string, you will get the default property builder:
Clicking the above ‘…’ will launch the default string property builder:
This popup is actually the ‘zoombldr.aspx’ page located in the _layouts virtual directory.
There are a few problems with this builder, well it’s not so much the builder, the string property’s of the web part are serialised in a manner that strips out carriage returns. So if you were to spend time formatting the contents of this dialog, it will get wiped out when you save the contents. This is most apparent when you edit the XSLT of the core search results web part.
How can you override this property?
The key is to make use of the HtmlDesigner attribute on your web part property. There are two ways to make use of the attribute, the first way is to explicitly define the page which you want to load (i.e. change ‘url to page’):
[System.Web.UI.WebControls.WebParts.WebBrowsable(true), System.Web.UI.WebControls.WebParts.WebDisplayName("Template"), System.Web.UI.WebControls.WebParts.WebDescription(""), System.Web.UI.WebControls.WebParts.Personalizable( System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared), System.ComponentModel.Category("Settings"), System.ComponentModel.DefaultValue("") ] [HtmlDesignerAttribute("url to page", DialogFeatures = "dialogHeight:500px;dialogWidth:650px;help:no;status:no;resizable:yes")] public string CustomProp { get { return customProp; } set { customProp = value; } }
Notice that you could also modify the parameters that get passed into the JavaScript popup window creation script, in the case above I have made the popup window larger than the default size. The problem with the above approach is that the URL that gets passed as the first parameter to the HtmlDesignerAttribute must be a constant value, since it’s used in the attribute declaration. However Microsoft have provided us with a nice way to change this behaviour.
[System.Web.UI.WebControls.WebParts.WebBrowsable(true), System.Web.UI.WebControls.WebParts.WebDisplayName("Template"), System.Web.UI.WebControls.WebParts.WebDescription(""), System.Web.UI.WebControls.WebParts.Personalizable( System.Web.UI.WebControls.WebParts.PersonalizationScope.Shared), System.ComponentModel.Category("Settings"), System.ComponentModel.DefaultValue("") ] [HtmlDesignerAttribute(BrowserBuilderType.Dynamic, DialogFeatures = dialogHeight:500px;dialogWidth:650px;help:no;status:no;resizable:yes")] public string CustomProp { get { return customProp; } set { customProp = value; } }
I’ve now added the BrowserBuilderType.Dynamic option. To get this to work, we now need to override the GetCustomBuilder method of your web part:
protected override string GetCustomBuilder(stringpropertyName) { if(propertyName == "CustomProp") { return"url.aspx?"+ "some custom params"; } return base.GetCustomBuilder(propertyName); }
Now every property that has BrowserBuilderType.Dynamic passed into the HtmlDesignerAttribute will get passed into the GetCustomBuilder method, this gives you the chance to create a URL that passes parameters to your custom builder page.
Ok, so now you got the web part covered, what about the JavaScript that needs to run on your custom property builder page?
The best thing to do is to look at the current zoomdldr.aspx page, when the page loads you can get the current arguments from:
window.dialogArguments
Then to save the arguments, save the string value back to:
window.returnValue
Now that you’ve got a fair idea about creating custom property builders, you can create builders that are specific to you needs, below is a screenshot of a property builder form that lets the user enter some c# code that gets compiled an injected into the web part, the need was to provide a nice interface that the end user (i.e. a programmer) could use. The property builder uses the EditArea control to format the code nicely. The user can then click the compile button which will do a compilation of the code and report any errors. I’ve also added some JavaScript code to get around the removal of the carriage return characters, which was a major pain point for us.
This approach will give you the power to create property builders that more closely suit your needs and goals.