我在更新面板下的页面中编写了以下代码.
protected void myGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
try
{
if (e.CommandName =="EditNames")
{
long lSelectedName = Convert.ToInt64(e.CommandArgument);
Session["SelectedItem"] = lSelectedName;
Response.Redirect("EditItem.aspx");
}
else if (e.CommandName =="DeleteNames")
{
long lSelectedName = Convert.ToInt64(e.CommandArgument);
ValidName.DeleteItem(lSelectedName);
ScriptManager.RegisterStartupScript(this, GetType(), "Key", "alert('Name deleted sucessfully')", true);
}
}
catch (System.Threading.ThreadAbortException)
{
}
catch (Exception ex)
{
Error handling code...
}
}
Run Code Online (Sandbox Code Playgroud)
在这里,我在重定向时遇到线程中止异常.但是,我通过使用错误处理程序解决了它System.Threading.ThreadAbortException.
但我不确定为什么在重定向时出现错误.即使我解决了这个问题,我想知道我编码的方式是否有任何错误,或者是否有任何方法可以阻止错误触发.
给你的意见......
请注意,该页面位于AJAX UPDATE PANEL下.
Moi*_*ala 28
而不是结束请求,通过调用,绕过请求执行管道是一个好习惯Context.ApplicationInstance.CompleteRequest().
所以你的代码看起来像这样:
Response.Redirect("TargetPage", false); //write redirect
Context.ApplicationInstance.CompleteRequest(); // end response
Run Code Online (Sandbox Code Playgroud)
Mik*_*oud 23
即使我解决了这个问题,我想知道我编码的方式是否有任何错误
没错,你做得很好.
预计会出现此错误.抛出它是因为重定向时服务器线程实际上已中止.从MSDN文档:
如果为endResponse参数指定true,则此方法为原始请求调用End方法,该方法在完成时抛出ThreadAbortException异常.
重定向调用End,在完成时抛出ThreadAbortException异常.
| 归档时间: |
|
| 查看次数: |
41349 次 |
| 最近记录: |