By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,385 Members | 847 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,385 IT Pros & Developers. It's quick & easy.

how to submit a form when enter is pressed

P: n/a
RTT
<form id="Form1" method="post" runat="server">
<asp:textbox id="TxtEmail" tabIndex="1" runat="server" Width="272px"
ToolTip="Enter your emailaddress for authentication"></asp:textbox>
<asp:textbox id="TxtPassword" tabIndex="2" runat="server" Width="272px"
ToolTip="Enter your domain password" TextMode="Password"></asp:textbox>
<asp:linkbutton id="BtnLogin" tabIndex="3"
runat="server">Login</asp:linkbutton>
</form>

This is the form as i use it for my user to enter thier login information.
But now they have to click the link in order to log in. Is it possible to
submit the form when 'enter' is pressed (like it's the case with input
type="submit" in standard html forms).

does anyone know how to do this?
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

You can use the following code for it:

<input type="submit" style="display:none;">

Also, you can use the foolowing method:

In your HTML code,

<script language="javascript">
function blockEnter(evt)
{

if (evt.keyCode == 13)
{

if (evt.srcElement.tagName=="TEXTAREA")
return true;
return false;
}
}

</script>

In the page's codebehind, add this code to the page's prerender event:

TextBox1.Attributes.Add("onKeyDown", "return blockEnter(event)")

HTH

Mona[Grapecity]


"RTT" <RT*@pandora.be> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
<form id="Form1" method="post" runat="server">
<asp:textbox id="TxtEmail" tabIndex="1" runat="server" Width="272px"
ToolTip="Enter your emailaddress for authentication"></asp:textbox>
<asp:textbox id="TxtPassword" tabIndex="2" runat="server" Width="272px"
ToolTip="Enter your domain password" TextMode="Password"></asp:textbox>
<asp:linkbutton id="BtnLogin" tabIndex="3"
runat="server">Login</asp:linkbutton>
</form>

This is the form as i use it for my user to enter thier login information.
But now they have to click the link in order to log in. Is it possible to
submit the form when 'enter' is pressed (like it's the case with input
type="submit" in standard html forms).

does anyone know how to do this?

Nov 21 '05 #2

P: n/a
RTT,

Set Form1.AcceptButton to the button you want clicket when enter is
pressed.

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.