views:

81

answers:

5

hi

Which one is better when we want to redirect to a new page in asp.net : using a link button and then Response.Redirect OR using an html link?

+3  A: 

well an anchor tag elimates a round trip to the server.

Christopher Kelly
At the same time... it eliminates a round trip to the server. Meaning you lose an opportunity to save data from the previous page in the context of that page. But +1, because you definitely do want to avoid un-needed round trips where ever possible.
Joel Coehoorn
A: 

I would use the anchor tag. It seems that with the redirect you are doing extra work with the round trip for not much gain besides using the link button control (at least this is what I am surmising from your question, there are valid reasons to use it). Also (not that this will likely make a difference in your case) it does cause and additional status code to be sent to the browser (302), telling the client application something is potentially amiss). If you are working on a highly secure site and or have non-browser applications accessing the page to pull information, this could be a problem.

Actually you have a third option which might suit your needs. Depending on the way your pages are setup and what you need to do, you can use Server.Transfer also.

Kevin
+10  A: 

Depends on your needs:

  • Use the <a> tag if there's no need for you to do anything with the form/page you're directing from
  • use response.redirect if you need information from the form before moving on to the next page, for example to update session states or store intermediate results.
Tom
Good answer, explains when you would use each of the two options well.
Garry Shutler
+1  A: 

If you are just linking to another page with a static URL, use an HTML anchor link. It will have better performance and only requires code in one place: the page.

If you need to perform operations on the server before the redirect, including manipulating the URL (e.g. dynamically creating querystring parameters), then use a server control (button, link, linkbutton).

NYSystemsAnalyst
A: 

If you want to use a button instead of a link just for the way it looks, you can use javascript to change the location of the page in the button's onclick also saving you a trip to the server.

jamesaharvey