asp.net:response.redirect无法正常工作

ana*_*nay 5 asp.net response.redirect

我有一个.aspx表单,其中我有一个组合框保存主题我从DB表中检索.

单击提交按钮,在网格视图中查看与该主题相关的问题.

我通过在按钮单击事件中调用函数FillGrid()来实现.

我也有pageindexchanging我的gridview,其中再次调用FillGrid().

在我的FillGrid()函数中,我使用了try catch块.如果发生错误,我想使用Response.Redirect()将页面重定向到错误页面.问题是这个response.redirect无效.其中一个原因是,在按钮点击时,表单会被发布两次.因为在到达response.redirect语句流后返回按钮单击调用FillGrid的地方().

我怎么解决这个问题?或简单地说,如何防止双重发布表单?

小智 6

例如,您需要链接index.aspx.所以你写这个:

Response.Redirect("index.aspx", true);
Run Code Online (Sandbox Code Playgroud)

但是Response.redirect没有用.现在转到设计视图选择要设置的按钮,Response.redirect然后按F4将打开按钮属性,然后您需要找到PostBackUrl选项,然后找到您想要的URL.

看这个图片:


Ode*_*ded 1

尝试这个:

Response.Redirect("url");
Response.End;
Run Code Online (Sandbox Code Playgroud)