当ApplyChanges返回false时,如何从EditorPart设置错误消息?

我正在使用WebPartManager开发一个自定义的ASP.Net WebPart,我也在创建一个自定义的EditorPart。 对于EditorPart.ApplyChanges方法每当出现错误时,我都会将返回值设置为false

在EditorZone中,我收到一条标准错误消息,指出编辑器发生了一些错误,但我想更改该消息。 那可能吗? 就像是…

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; } } 

我在社交msdn中找到了一个解决方案,但我不确定它是否正确,因为它没有很好的文档记录。 您必须在PreRender方法中设置错误,如下所示:

 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}
{1}", this.Zone.ErrorText, _errorText); } base.OnPreRender(e); }