问题描述
我使用WebPartManager的开发自定义ASP.Net Web部件,我创建一个自定义的EditorPart了。对于它的 EditorPart.ApplyChanges 方式我在返回值设置为false 只要有一个错误。
在EditorZone我得到这表明发生了一些编辑错误的标准错误消息,但我想改变该消息。
是可能的吗?喜欢的东西...
公共覆盖布尔ApplyChanges()
{
试
{
//保存特性
返回真;
}
赶上(异常前)
{
的ErrorMessage = ex.Message; //是否有任何类似的财产,我可以填?
返回FALSE;
}
}
我已经找到一种解决方案在的,但我不知道这是正确的,因为它没有很好的记录。你必须设置错误的prerender方法,像这样:
字符串_errorMessage;
公众覆盖布尔ApplyChanges()
{
试
{
//保存特性
返回真;
}
赶上(异常前)
{
_errorMessage = ex.Message; //是否有任何类似的财产,我可以填?
返回FALSE;
}
}
保护覆盖的OnPreRender(EventArgs五)
{
如果(!string.IsNullOrEmpty(_errorText))
$ { b $ b this.Zone.ErrorText =的String.Format({0}< BR /> {1},this.Zone.ErrorText,
_errorText);
}
base.OnPreRender(E);
}
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;
}
}
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);
}
这篇关于如何在ApplyChanges返回false设置的EditorPart从一个错误信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!