Engage on Facebook Engage on Twitter Engage on LinkedIn Engage on GitHub components notes mobile card heart 2 infinite mirror 2 pricing support

DotNetNuke and Browser-Independent Default Buttons

By Brian Dukes

When you have multiple submittable forms on a web page (such as a search and a checkout), you have to somehow let the browser know which form to submit when the user presses .  ASP.NET provides a DefaultButton property off of the Panel control, which is supposed to let you define which button to submit through if the user presses <enter> while the focus is in that panel.  However, it doesn't work in Firefox, so you have to keep searching if you're building any sort of public-facing website.

ClientAPI to the rescue!  We did a little poking around and found the RegisterKeyCapture method in DotNetNuke's ClientAPI.  This takes an input control (such as a text box), a postback control (such as a button) and an ASCII key identifier.  So, to make your search box work, it's ClientAPI.RegisterKeyCapture(txtSearch, btnSearch, 13); since 13 is the ASCII code for <enter>.  There's also an override that takes plain ol' javascript instead of a postback control.

Enjoy!

Planning a DNN upgrade? Download our guide