Tuesday, August 17, 2010

ASP.NET 2.0 AND DefaultButton?

This is a long question, so be prepared...





I am working with an ASP.NET 2.0 web application. I have a form with a textbox, a cancel button, and a continue button. I want the continue button to be the default, and I want th textbox to have the focus when the form loads. I set the form DefaultButton and DefaultFocus attributes to btnContinue and txtTextBox repsectively.





When the form loads, the cursor is in the textbox, but the cancel button has the emphasized border. When I hit the enter key, the continue button fires like I expect. The problem is that the cancel button LOOKS like it is the default.





I trued using JavaScript to set the focus to the continue button. This is okay, but then, when the user clicks in the textbox, the cancel button again has the emphasized border. Again, the enter key press will fire the continue button as expected.





Am I crazy, or is this harder than it should be? Any help would be greatly appreciated.

ASP.NET 2.0 AND DefaultButton?
Have you tried giving it a lower tab index, when you created the form perhaps you put the cancel button on before the continue and it's tab index comes first. I haven't ran it to this problem before, so I'm not sure if that will solve it.


No comments:

Post a Comment