I need to press the enter key when the user presses the button. 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 putting it this way, but it 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 nothing happens either.
<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" />