Virtually every ASP.NET developer has, at one point or another, created a page with a Button control that, when clicked, redirects the user to some other page, perhaps sending along a value entered by the user through the querystring. The typical pattern for implementing such behavior is to add a Button to the page and create a Click event handler that executes a Response.Redirect( url ) . If the redirect incorporates some input from the user, then this pattern is expanded to include the addition of a TextBox or some other control to the page and a Response.Redirect( url ) statement that includes this control’s value. While this approach certainly works, it’s not without a couple of flaws. Firstly, this approach involves a needless round-trip to the server: clicking the Button causes the browser to re-request the page and the response from the server is simply, “Please go to url .” Ideally, when the Button was clicked the browser would immediately request the final destination URL rather than have to do a postback to find out the final destination URL. Second, this approach can lead to a confusing user experience in scenarios where there are multiple TextBoxes on the page and multiple Buttons because there may not be the expected correspondence between hitting Enter in a TextBox and having the associated Button control “clicked.” Consider a website with a master page that has a TextBox and Button for searching the site.

Share and Enjoy:
  • Digg
  • Google
  • Technorati
  • Facebook
  • MySpace
  • TwitThis
  • Blogsvine
  • description
  • E-mail this story to a friend!
  • Print this article!
  • Slashdot
  • Yahoo! Buzz