Creating a refresh meta header in the code behind to redirect to another page

Category ASP.Net Sub Category Page Interaction
Bookmark and Share
This technique allows you to call up another page if for instance a certain condition is met. By delaying the call to this allows the existing page to be initially displayed. Could be used in a scenario where the status of something being processed on that page is wrong and you need to tell the user this and then direct them to another page, that will allow them to fix the status.
Copy Code
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim NeedToChangePage As Boolean = True If NeedToChangePage Then lblMessage.Text = "You will be redirected to <a href=""/RedirectPage.aspx"">" & _ "Redirect Page</a> in 5 seconds..." 'redirect to another page on page load 'delay this by 5 seconds to show message from this page Response.AddHeader("REFRESH", "5;URL=/RedirectPage.aspx") End If End Sub


Note some concerns with using this technique:

If the redirect happens quickly (less than 3 seconds), readers with older browsers can't hit the "Back" button. This is a usability problem.

Refreshing the current page can confuse people. If they didn't request the reload, some people can get concerned about security seeing the page seemed to change wihtout the user asking.
Share the love
Bookmark and Share