DefaultButtons for Asp:Login and Asp:CreateUserWizard

Today, I was tasked with making some Asp:Login and Asp:CreateUserWizard controls work. Specifically, the enter button was acting with an effluence inherent only to[1]: it was submitting the search button.

After playing with various schemes, I settled upon the following for the Login control:

<asp:Panel ID="pnlLogin" runat="server" DefaultButton="lgMain$LoginButton">
    <asp:Login runat="server" ID="lgMain" />

I originally thought that the same would work for the CreateUserWizard, and it turns out I was correct. But we were using a version of CssFriendlyAdapter which was slightly broken. It was outputting the buttons with one less underscore than it should have: so I made changes on lines 409 and 426 of CreateUserWizardAdapter.cs, adding an extra underscore to the "__CustomNav0" output.

I then used this for the registration page:

<asp:Panel runat="server" DefaultButton=
    <cog:CreateUserWizard runat="server" ID="cuwMain" />

And all was well in the world. Except for those unlucky people without Javascript enabled.

Update 2009-06-25: today I had to do the PasswordRecovery control as well. This was a bit different because depending on what state the control was in, a different button had to be set as default.

I hooked into the events for VerifyingUser and AnswerLookupError and set the default button to the QuestionContainer submit button, and for UserLookupError and default set it to the default UserNameContainer button.

I first attempted to create a Panel-like control that iterates through its children and sets the default button to the first visible button, but that was unfruitful because PasswordRecovery does not set its children’s visibilities until render. I now imagine that the best possible solution — aside from not using or these controls — would be a Javascript onkeypress handler like the Panel’s one, but just finds the first visible button when enter is hit.

[1]: For more information on the inherent effluence of, check out this article that seems to claim that Microsoft suggest using Javascript to fix their broken RadioButton implementation.

Leave a Reply