0
I need that when the user presses the enter key, do the button click event. I’m doing it this way, but it’s not working in Google Chrome or firefox:
     if (!IsPostBack)
            {
                txtsenha.Attributes.Add("onkeydown", "if(event.which || event.keyCode){if ((event.which == 13) || (event.keyCode == 13)) {document.getElementById('"+btnEntrar.UniqueID+"').click();return false;}} else {return true}; ");
            }I also tried to put this way below, but also does not work in Google Chrome and firefox.
  <asp:Panel ID="Panel2" runat="server" DefaultButton="btnEntrar">
                        <div class="col-xs-6">
                            <div class="input-group">
                                <asp:TextBox ID="Empresa" class="form-control" runat="server" placeholder="Código da Empresa"></asp:TextBox>
                                <span class="input-group-addon">
                                    <button class="fa fa-industry" style="background: transparent; border: none"></button>
                                </span>
                            </div>
                        </div>
                        <br />
                        <div class="col-xs-7">
                            <div class="input-group">
                                <asp:TextBox ID="txtIdent" class="form-control" runat="server" placeholder="Identificador"></asp:TextBox>
                                <span class="input-group-addon">
                                    <button class="fa fa-user fa-lg" style="background: transparent; border: none"></button>
                                </span>
                            </div>
                        </div>
                        <br />
                        <br />
                        <div class="col-xs-8">
                            <div class="input-group">
                                <asp:TextBox ID="txtsenha" class="form-control" runat="server" type="password" placeholder="Senha" AutoPostBack="False" OnTextChanged="txtsenha_TextChanged"></asp:TextBox>
                                <span class="input-group-addon">
                                    <button class="fa fa-unlock-alt fa-lg" style="background: transparent; border: none"></button>
                                </span>
                            </div>
                        </div>
                        <br />
                        <asp:Button ID="btnEntrar" runat="server" Text="Entrar " CssClass="radius" OnClick="btnEntrar_Click" />
                    </asp:Panel>I made this adaptation in the code, but also nothing happens.
    <script type="text/javascript">
        jQuery(document).ready(function () {
            jQuery('#txtsenha').on('keypress', function (e) {
                if (e.keyCode == '13') {
                    jQuery('#btnEntrar').trigger('click');
                }
            })
            jQuery('#btnEntrar').click(function () {
                alert('Click!');
            });
        });
    </script><div class="col-xs-8">
                        <div class="input-group">
                            <asp:TextBox ID="txtsenha" class="form-control" runat="server" type="password" placeholder="Senha" AutoPostBack="False" OnTextChanged="txtsenha_TextChanged"></asp:TextBox>
                            <span class="input-group-addon">
                                <button class="fa fa-unlock-alt fa-lg" style="background: transparent; border: none"></button>
                            </span>
                        </div>
                    </div>
                    <br />
                    <asp:Button ID="btnEntrar" runat="server" Text="Entrar " CssClass="radius" OnClick="btnEntrar_Click" />
Have you tried using the Defaultbutton="myButton" property? Read more here: https://stackoverflow.com/questions/7638119/how-to-set-a-default-enter-on-a-certain-button
– Jhonathan
I’m trying that way too, but nothing happens.
– Mariana
Post your aspx code to see if I can help you.
– Jhonathan
I changed it including the Aspx code, thank you.
– Mariana
I really couldn’t see why it didn’t work. Read this link for help: https://www.codeproject.com/Articles/17241/Capturing-the-Enter-key-to-cause-a-button-click#_comments
– Jhonathan
Jhonathan I checked the problem is in Google Chrome browsers and Firefox. In IE works normal. But I needed it to work in all these browsers. I’ll see this link q passed me.
– Mariana