[英]how to give prompt message & after that redirecting page to another in button click event in asp.net
[英]Redirecting after click on button throws error ASP.NET
我使用常规按钮将跨度放入按钮中。 我还制作了 onServerClick 函数(用于处理事件)。
<button id="btnCancel" runat="server" class="btn btn-default pull-right" onserverclick="btnCancel_Click"><span class="glyphicon glyphicon-remove text-magenta"></span>Cancel</button>
这应该是简单的取消按钮,应该退出表单并注意其他内容。 但由于某种原因,C# 函数在重定向时抛出异常。
这是功能:
try
{
Response.Redirect("StartPage.aspx");
}
catch (Exception ex)
{
NLog.LogManager.GetCurrentClassLogger().Warn("Error happened", ex);
Response.Redirect("Error.aspx", false);
}
另外,如果我只是不尝试并捕获块,一切正常。
Response.Redirect
抛出一个被您的异常处理程序捕获的ThreadAbortException
。 任何一个
Response.Redirect
移出异常处理程序或ThreadAbortException
创建一个专用处理程序:try
{
Response.Redirect("StartPage.aspx");
}
catch (ThreadAbortException)
{
// Exception is expected, do nothing
}
catch (Exception ex)
{
NLog.LogManager.GetCurrentClassLogger().Warn("Error happened", ex);
Response.Redirect("Error.aspx", false);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.