wilcor14
asked on
onkeyPress does not work in FF or Safari
The code below works in IE but not in FF or safari. Basically when a user has entered the username and password and enter is hit, the submit button should be triggered. Is there a way we can do this in FF? Thanks.
<div onkeypress="if (event.keyCode == 13) document.getElementById('ctl00_LoginView1_Login1_btnLogin').click();">
<asp:TextBox ID="UserName" runat="server" Font-Names="Verdana" Font-Bold="True" Font-Size="XX-Small"
BorderWidth="1px"></asp:TextBox>
</div>
ASKER
Thanks for the input.
I put the onKeyPress within the TextBox tag but it did not work. The code behind didn't work either. Any other suggestions?
I put the onKeyPress within the TextBox tag but it did not work. The code behind didn't work either. Any other suggestions?
Sorry...
add defaultbutton attribute to form tag.
<form id="form1" runat="server" defaultbutton="button1">
add defaultbutton attribute to form tag.
<form id="form1" runat="server" defaultbutton="button1">
ASKER
That didn't work but what does work is if I put the following:
I also put the code I have for my login button. Thanks
I also put the code I have for my login button. Thanks
<asp:TextBox ID="txtUserName" runat="server" Font-Names="Verdana" Font-Bold="True" Font-Size="XX-Small"
onkeypress="if (event.keyCode == 13) alert('enter');" BorderWidth="1px"></asp:TextBox>
<asp:LinkButton ID="btnLogin" OnClick="btnLogin_Click" Text="Member Login" runat="server"
CommandName="Login" ValidationGroup="Login1"> Login </asp:LinkButton>
Hmm...this works for me.
<%@ Page Language="C#" AutoEventWireup="true" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnLogin_Click(object sender, EventArgs e)
{
label1.Visible = true;
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server" defaultbutton="btnLogin">
<div>
<asp:Label ID="label1" runat="server" Text="Button 1 Clicked" ForeColor="Red" Visible="false"></asp:Label>
<hr />
<asp:TextBox ID="textBox1" runat="server"></asp:TextBox>
<hr />
<asp:LinkButton ID="btnLogin" runat="server" Text="Login" OnClick="btnLogin_Click"></asp:LinkButton>
</div>
</form>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Aha, that gave me an idea,
I added the following:
<asp:Button ID="btnHiddenLogin" OnClick="btnLogin_Click" Text="Member Login" runat="server"
CommandName="Login" ValidationGroup="Login1" style="display:none;" />
Now I can use .click(); and it will work.
The reason I don't want to use the defaultbutton option is because I have my login options in my masterpage and that complicates when users hit return when they are on other pages. But this work around works good. thanks.
I added the following:
<asp:Button ID="btnHiddenLogin" OnClick="btnLogin_Click" Text="Member Login" runat="server"
CommandName="Login" ValidationGroup="Login1" style="display:none;" />
Now I can use .click(); and it will work.
The reason I don't want to use the defaultbutton option is because I have my login options in my masterpage and that complicates when users hit return when they are on other pages. But this work around works good. thanks.
You can also do it in code-behind, which might be better, using
UserName.Attributes["onKey