Asp.net: response.redirect not working

I have a .aspx form in which I have an object for selecting a list with a list that I retrieve from a DB table.

The submit button, clicking on which raises questions related to this object, in the form of a grid.

I do this by calling the FillGrid () function in a button click event.

I also have a pageview for my gridview in which FillGrid () is called again.

In my FillGrid () function, I used a catch try block. If an error occurs, I want to redirect the page to the error page using Response.Redirect (). The problem is that this response.redirect is not working. One reason for this is that when you click a button, the form is published twice. Because after reaching the response.redirect reaction, the stream returns to pressing the button where FillGrid () is called.

How can i solve this? Or just saying how can I prevent duplicate form posting?

+3
source share
5 answers

For example, you need to bind index.aspx. So you write this:

Response.Redirect("index.aspx", true);

Response.redirect . , , Response.redirect, F4, , PostBackUrl, URL-.

:

g1DZc.png

+5

, ...

Response.Redirect("~/err.aspx", false);
HttpContext.Current.ApplicationInstance.CompleteRequest();

​​ , . Response.Redirect("~/err.aspx", true); , , catch.

• , , Server.Transfer(), , .

+2

. , . :

FormsAuthentication.SetAuthCookie(loginUserDetail.UserName, false);
Response.Redirect(FormsAuthentication.DefaultUrl, false);

FormsAuthentication.DefaultUrl "/membersarea/wellcome.aspx", wellcome.aspx Site.master.

Site.master javascript, Response.Redirect .

+1

:

Response.Redirect("url");
Response.End;
0

, , , . . . , , , . page_load ( ASP.NET).

Although you can use Server.Transfer to get around this, I would recommend using the error forwarding built into ASP.NET. See this page for more information on what is available and how to use them.

0
source

Source: https://habr.com/ru/post/1724297/


All Articles