Menu

Want to work with us? We're on the lookout for a UX/UI Designer and Digital Project Manager.

We're hiring

Enter Key Press On Control Firefox Issue ASP.Net

Web Bureau


17 November 2010 by Web Bureau

.NET Framework 3.5

Been having an issue trying to sort this problem out. The scenario is that i have multiple textboxes on screen that should replicate the mouse click submit behaviour on a button when the enter key is pressed.

Everything i tried didnt work until i found this piece of code below. I think it incorporates 2 solutions on is the use of a panel around the text box in question with the default button set and the other is the inclusion of the javascript file.

I hope this is of use to others with the same issue.

<asp:Panel ID="pnl_Search" DefaultButton="btn_Search" runat="server">

                   <div class="txtbox_outer"><asp:TextBox ID="str_Search" runat="server" CssClass="txtbox"></asp:TextBox></div>

                   <div class="signin_btn"><asp:LinkButton ID="btn_Search"  runat="server" CssClass="search_btn" Text="Search"></asp:LinkButton></div>                 

                   <cc2:TextBoxWatermarkExtender ID="TextBoxWatermarkExtender1" runat="server" TargetControlID="str_Search" WatermarkText="Enter Search Text..."></cc2:TextBoxWatermarkExtender>

</asp:Panel>


 // Javascript Fix for enter key press firefox ====================


  $(function () {
         var b = document.getElementById('<%= btn_Search.ClientID %>');
         if (b && typeof(b.click) == 'undefined') {
            b.click = function() {
               var result = true;
               if (b.onclick) result = b.onclick();
               if (typeof(result) == 'undefined' || result) {

                  eval(b.getAttribute('href'));

               }
            }
         }
      });

Grow your businessStart a project with us today.