UpdatePanel的异常处理 [英] UpdatePanel Exception Handling

查看:84
本文介绍了UpdatePanel的异常处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当异常发生在我的ASP.NET web应用程序我建立实施的UpdatePanel,它们会导致页面上的JavaScript错误与警报提供一些高级别的错误输出。这是OKish发展,但只要该系统是集生产,这显然是有多种原因没有好处。我可以与周围尝试捕捉等来控制JavaScript错误麻烦的活动,但在某些情况下,我想利用主页等的行动来支持用户的体验。

Where exceptions occur in the UpdatePanels I've implemented in the ASP.NET web app I'm building, they cause a JavaScript error on the page with some high level error output available in the alert. This is OKish for development, but as soon as the system is in Production, it's obviously no good for multiple reasons. I can surround troublesome activities with Try Catch etc to control the Javascript error but in some cases, I want to take actions on the main page etc to support the user experience.

我该如何去有关操作中出现的错误的UpdatePanel优雅地提供无缝和JavaScript错误免费实现?

How do I go about handling errors that occur in UpdatePanels gracefully to provide a seamless and Javascript error free implementation?

推荐答案

您可以使用上的ScriptManager(服务器端)的AsyncPostBackError事件的组合,在PageRequestManager(客户端)的EndRequest事件完全处理服务器使用的UpdatePanel时,机端的错误。

You can use a combination of the AsyncPostBackError event on the ScriptManager (server-side) and the EndRequest event on the PageRequestManager (client-side) to fully handle server-side errors when using the UpdatePanel.

下面有几个资源可以帮助你:

Here are a couple resources that should help you:

自定义错误处理ASP.NET UpdatePanel控件

错误处理定制的ASP.NET的UpdatePanel

下面是一个简单的例子:

Here's a simple example:

// Server-side
protected void ScriptManager1_AsyncPostBackError(object sender, 
    AsyncPostBackErrorEventArgs e)  {
    ScriptManager1.AsyncPostBackErrorMessage =
        "An error occurred during the request: " +
        e.Exception.Message; 
}


// Client-side
<script type="text/javascript">
  function pageLoad()  {
    Sys.WebForms.PageRequestManager.getInstance().
        add_endRequest(onEndRequest);  
  }

  function onEndRequest(sender, args)  {
    var lbl = document.getElementById("Label1");
    lbl.innerHTML = args.get_error().message;
    args.set_errorHandled(true);
  }
</script>

这篇关于UpdatePanel的异常处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆