Suppose I define a web part property like this:
private string _myString = "default value";
[WebBrowsable(true),
WebDisplayName("My string"),
WebDescription("A simple bit of text to set"),
Personalizable(PersonalizationScope.User),
DefaultValue("My default value"), //this doesn't work for some reason
Category("My properties")]
public string MyString
{
get
{
return _myString;
}
set
{
if(string.IsNullOrEmpty(value))
throw new Microsoft.SharePoint.WebPartPages.WebPartPageUserException("String must not be empty");
_myString = value;
}
}
This is how it is explained in various guides and books. The WebPartPageUserException is supposed to cause the validation text to appear in the web part properties pane in the side. For visual web parts, this works like a charm. However, for 'classic' web parts in a sandboxed solution, the page will reload and the web part will display an error about an unhandled exception.
Is this validation inside the properties pane really restricted to visual web parts, or am I missing something? It seems strange how something like this would be impossible in sandboxed solutions.