问题
I'm developing a custom ASP.Net WebPart using the WebPartManager and I'm creating a custom EditorPart too. For its EditorPart.ApplyChanges method I set the return value to false whenever there is an error.
In the EditorZone I get a standard error message indicating that some error happened to the editor, but I want to change that message. Is that possible? Something like...
public override bool ApplyChanges()
{
try
{
// save properties
return true;
}
catch(Exception ex)
{
ErrorMessage = ex.Message; // is there any similar property I can fill?
return false;
}
}
回答1:
I've found one solution in social msdn, but I'm not sure it is correct because it is not very well documented. You have to set the error in the PreRender method, something like this:
string _errorMessage;
public override bool ApplyChanges()
{
try
{
// save properties
return true;
}
catch(Exception ex)
{
_errorMessage = ex.Message; // is there any similar property I can fill?
return false;
}
}
protected override OnPreRender(EventArgs e)
{
if (!string.IsNullOrEmpty(_errorText))
{
this.Zone.ErrorText = string.Format("{0}<br />{1}", this.Zone.ErrorText,
_errorText);
}
base.OnPreRender(e);
}
来源:https://stackoverflow.com/questions/2921491/how-to-set-an-error-message-from-editorpart-when-applychanges-returns-false