When Should We Use Response.Redirect(url,false) in C# code?

In this article, we are going to learn about Response.Redirect() in C#.

So, Response.Redirect() may accept 2 parameters, one is the URL and another one is a boolean value i.e. True or False.

What is the use of True and False in Response.Redirect?

The first parameter in Response.Redirect() define redirection to the next page. And the second parameter true/false tells whether to stop or continue processing the next line.

In other words, the True or False parameter of Response.Redirect tells whether to continue the code execution or terminate the next line execution on that page.

Let’s look at the below piece of code:

Response.Redirect("Page.aspx",false);
 for (int i = 0; i < 10; i++)
     {
        i++;
     }

In the code snippet, after Response.Redirect the for-loop execution will continue.

Let’s look at another code snippet:

Response.Redirect("Page.aspx",true);
 for (int i = 0; i < 10; i++)
    {
       i++;
    }

Here, after Response.Redirect for-loop execution will terminate. This is because we are passing true as the second parameter to Response.Redirect()

Leave a Comment

RSS
YouTube
YouTube
Instagram