Firefox, LinkButtons, and the Panel.DefaultButton: a (Prototype) fix

Recently I’ve stepped away from the MonoRail world to work on a project that uses ASP.Net WebForms. It didn’t take long before I found an annoying problem. (Actually I found many annoying problems, but I’ll focus on one here.)

The <ASP:Panel> control has a DefaultButton property which, according to the documentation, "Gets or sets the identifier for the default button that is contained in the Panel control." In other words:

Use the DefaultButton property to indicate which button gets clicked when the Panel control has focus and the user presses the ENTER key.

It works perfectly, if you’re not using a LinkButton control. Actually, that’s not true; if you use a LinkButton control and Internet Explorer, it works fine. It just doesn’t work in Firefox. Why?

Dmytro Shteflyuk outlines why in his blog post, Using Panel.DefaultButton property with LinkButton control in ASP.Net. Apparently, it’s an issue with the JavaScript code that Microsoft generates, which expects a click() method on the anchor (i.e. LinkButton). Firefox doesn’t have such an event for anchors — at least, not by default.

Dmytro outlines a fix which requires you to injext some JavaScript for each button. I prefer a simpler approach using CSS selectors, so I wrote the following script (Prototype required) to do it. Simply add this script to your web page, add the CSS class "button" to each LinkButton control, and press ENTER on your Firefox forms.

Popularity: 29% [?]

Related Posts

Free market competition, unfettered by unnecessary governmental regulatory restraints, is the best way to foster innovation and development of the Internet. Free market competition drives scarce resources to their fullest and most efficient use, spurring businesses to invest in and sell as efficiently as possible the kinds and quality of goods and services that consumers desire. ast experience has demonstrated that, absent actual market failure, the operation of a free market is a far superior alternative to regulatory restraints.

-- Department of Justice

Comments 1

  1. Tristan wrote:

    Perfect!

    Thanks so much for posting this - it’s just what I was looking for. NB, if you’re using Mootools instead of/as well as prototype, then change the last line to:

    window.addEvent( ‘load’, prepareLinkButtonClicks );

    Posted 07 Aug 2008 at 5:56 pm

Post a Comment

Your email is never published nor shared. Required fields are marked *