views:

59

answers:

2

Hi

I have a problem in IE. Hitting enter when the focus is on the last input control sends the focus to the "Next" button. This submits the form. So far, so good.

The code in my base class WizardController looks to see if the Next submit button is null, as follows:

        protected string NextButton 
        {
            get 
            { 
                return ControllerContext.HttpContext.Request.Params["NextButton"];Nex
            }
        }

However, despite the form submitting, this property returns null unless the user explicitly clicks on the button with his mouse.

This is blatantly wrong, but I have no idea why it is happening.

EDITED TO SPECIFY THE PRECISE PROBLEM:

The problem only occurs IF there is ONLY one TEXT input control in the HTML form that gets rendered to the browser.

END EDIT

Andrew

A: 

A simple work around might be to use a hidden form element and depend on that rather than the button.

<input type='hidden' name='action' value='next' />

If you have multiple buttons you can always use JavaScript to change the value of the action element just before submitting.

Matthew Smith
Not sure how your answer relates to my question? Ie, how would this prevent the form submitting if the user presses enter? And is this a known bug in IE?Also, any solution shouldn't involve using JavaScript: it has to work with or without.
awrigley
By putting in the hidden field, you don't need to prevent submission by pressing enter. The problem is that pressing enter submits the form, but without the 'next' button data, right? So just add another hidden form element and use that instead of 'nextButton'. As for the JavaScript, you'd only need/want that if you have more than one submit button (e.g. 'Next' and 'Previous'), though why you would refuse to use JS I can't imagine.
Matthew Smith
The problem is only with IE. In all other browsers, it works fine. My wizard framework works builds up a notion of the current, next and previous steps using reflection rather than attributes of an input control, so the form submission has to happen with a Submit button. Everything is working (including auto generated sidebars) except for this one "bug". I really don't think your suggestion will work given the framework I have built, but thanks for the suggestion and I will keep it on file.
awrigley
My framework is Ajax enabled, but if JS isn't there, it still has to work. All the buttons, Next, Previous and the Side Bar navigation buttons are Submit buttons, but as the framework "knows" what steps there are and what order they are in, it doesn't need JS to work. The ONLY issue, is this one with IE: pressing enter when the focus is on the last control (bar the submit buttons) will submit the form as if the Next button was clicked (the expected behaviour of all other browsers), but this is not in the Request.Form Params when using IE. So no "refusal" to use JS.
awrigley
+1  A: 

I have finally found an explanation for my problem:

It seems to be a bug in IE, whereby if there is a single text input in the rendered HTML form, then IE will not submit the form properly. The issue is described (briefly) at:

Form Submit via Enter Key when using IE

In the above link, no description is given as to why the bug occurs, or since what version of IE, so a blanket solution is better.

The workaround suggested in the article is to add a css hidden text input (with conditionals for IE):

<!--[if IE]>
  <input type="text" style="display: none;" disabled="disabled" size="1" />
<![endif]-->

This worked for me, so issue solved.

The following is included to document the issue as I experienced it:

Unlike the problem described in the article, my form did submit. However, when I tried to check which button had been accessed by hitting tab or enter key, no submit button was in the HttpContext.Request.Params collection. So the behaviour I saw was slightly different.

What the above article did identify is that this behaviour is only seen WHEN there is ONLY one text input control. A single check box, for example, does not cause the problem.

I hope that this documents the problem adequately... and that MS will one day correct the bug.

awrigley