Redirecting to Another Page in ASP.NET , e.g website with different languages
You might want to redirect users from one ASP.NET Web page to another Web page. For example, you might do this as part of a multi-page form.
There are a number of ways to redirect pages, such as the following:
There are a number of ways to redirect pages, such as the following:
- By configuring the page to post to another page In this scenario, the user clicks a button that you have configured to post to a different page. This scenario is useful for multi-page forms. However, it requires user interaction. For details, see Cross-Page Posting in ASP.NET Web Pages.
- By dynamically using the browser In this scenario, you send a command to the user's browser that causes the browser to retrieve a different page. This allows you to programmatically redirect to another page. However, the redirection causes a new request (an HTTP GET), and any post data from the source page is lost.
To redirect a user to another page by using the browser
- Set the Response object's BufferOutput property to true.
- Call the Response object's Redirect method, passing it the URL of the page to which you want to redirect users.
Response.BufferOutput = true; if (UserLanguage == "English") { Response.Redirect("http://www.microsoft.com/gohere/look.htm"); } else if (UserLanguage == "Deutsch") { Response.Redirect("http://www.microsoft.com/gohere/look_deu.htm"); } else if (UserLanguage == "EspaƱol") { Response.Redirect("http://www.microsoft.com/gohere/look_esp.htm"); }
To redirect users to another page by using a server-side method
Call the Transfer method, passing it the name of the page to which you want to redirect users.
protected void Button1_Click(object sender, System.EventArgs e) { Server.Transfer("Page2.aspx", true); }
Comments
Post a Comment