How to redirect to another page using ASP.NET?

I know this is a simple question, but I really can't find anything on Google. Sorry if I'm not looking for the right. I created 2 pages, and in the first - a button.
What should I write in C # code to change in order to redirect me to the second page?
I usually know my way around C #, but I'm completely new in ASP.

+4
source share
4 answers

Not quite sure about your question whether you will be after ASP VB or C # ... therefore ...

//FROM#

 private void Button1_Click(object sender, System.EventArgs e) { Server.Transfer("Webform2.aspx"); } 

'Visual Basic

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Server.Transfer("Webform2.aspx") End Sub 

For more information, I refer you:

http://msdn.microsoft.com/en-us/library/540y83hx%28VS.71%29.aspx

+4
source

You can also do this in aspx itself (without writing any code) using the PostBackUrl property of the button.

+2
source

Use one of the following methods:

One-time redirect (HTTP 301)

 Response.Redirect("page to redirect to"); 

Permanent redirect (HTTP 302), available only in ASP.NET 4.0

 Response.RedirectPermanent("page to redirect to"); 
+2
source

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


All Articles