Hi there, I could use a bit of assistance. My goal is to allow users to log in by hitting the "Enter" key on their keyboard. While I've successfully detected when the "Enter" key is pressed in my JavaScript code, I'm struggling with how to call my C# function. I understand that JavaScript runs on the client side and my C# code is on the server side, so I need some sort of PostBack mechanism. However, I haven't been able to get it to work consistently across all browsers.
This is the code I have written so far:
A button ...
<asp:Button ID="Button2" CssClass="btn" runat="server" type="submit" Text="Sign in"
OnClick="btnSubmit_Click" />
And here's my JavaScript:
$(document).keypress(function (e) {
var target = document.getElementById("MainContent_Button2");
if (e.which == 13) {
__doPostBack('btnSubmit_Click', 'sender, null');
}
});
Could you kindly point me in the right direction?