Wednesday, January 09, 2008

Scott Mitchell: Two Common Pitfalls When Submitting a Web Form Using the Enter Key

Itt van az egesz, de ami a lenyeg:

A regular button has a type attribute value of “button”. By default, the ASP.NET Button Web control renders a submit button.

Multiple Submit Buttons on the Page
…when a user hits Enter in a single-line textbox, the browser submits the form. In most situations, the browser includes the submit button’s name/value pair in the form fields returned on submission (although this is not always the case, as we’ll see later on in this article). If there are multiple submit buttons on the form, the browser sends the first submit button’s name/value pair on form submission (the first one being the one that first appears in the rendered HTML markup, not necessarily the one that appears visually first on the page).

Imagine that you have a page that collects user input and everything works fine. The user can hit Enter to submit the form, which causes the browser to send the submit button’s name/value pair, which executes the corresponding Button’s Click event handler, where you process the user’s entered data. Great. But what would happen if you (or a coworker) updated the site’s master page and included an ASP.NET Button control that, when clicked, would, say, Response.Redirect the user to a Login page? With this change, if a user visited your form and hit Enter to submit it, the browser would send the Login submit button’s name/value pair, and the user would be redirected to the login page!

The net result is that the Login Button’s Click event is raised on postback, and the user is sent to the Login page. Talk about a confusing user experience! Everything works fine if they click the “Submit Form” button, but if they hit Enter, they are redirected to the Login page.

To fix this, we need to instruct the Login Button control that it should not render as a submit button, but rather a regular button. To accomplish this, set the Login Button’s UseSubmitBehavior property to False. This causes the Login button to render as a regular button along with the necessary JavaScript to submit the form when the button is clicked (along with sending additional information so that ASP.NET knows that that button was what caused the postback so that its Click event handler can be raised).

Using Enter to Submit a Form with Only One Single-Line TextBox
Another gotcha involving submitting forms with the Enter key arises with Internet Explorer and forms with just one single-line TextBox. Earlier I said that when hitting Enter in a single-line textbox, the browser submits the form and (usually) includes the first submit button’s name/value pair in the form submission information. Unfortunately, this is not the case when using Internet Explorer and a Web Form with just one single-line TextBox. A more thorough description of this problem is documented in an earlier article of mine, Enter and the Button Click Event.

In short, the workaround is to never create a Web Form with just one single-line TextBox. If your form only requires one single-line TextBox, then add another one but use Casecading Stylesheets (CSS) to hide it…Yes, it’s a hack, but it works.

Monday, January 07, 2008

Kalid Azad: An Intuitive Guide To Exponential Functions & E

Latvanyos magyarazat ezekkel a celokkal:
  • Explain why e is important: It’s a fundamental constant, like pi, that shows up in growth rates.
  • Give an intuitive explanation: e lets you see the impact of any growth rate.
  • Show how it’s used: e^x lets you predict the impact of any growth rate and time period.
  • Get you hungry for more: In the upcoming articles, I’ll dive into other properties of e.