473,387 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

<enter> key and form submit

Hi,
I have a web form which has:

- Login area with
- email textbox
- password textbox
- <enter> button to log in

- search area with
- string to search for textbox
- <search> button

How can I make this work so that when a user presses <Enter> in:

1) either email or password textbox, I can handle the log in function
which happens on the <enter> button Click() event
2) search textbox, the <search> button Click() event happens

??

TIA,
george
Nov 18 '05 #1
5 1997
You can intercept the client side enter keypress event of the text box and
then click do what you want using javascript code.
Here's a good example:
http://www.kamp-hansen.dk/pages/show...d=21&menuid=18

You could also try using this free control.
http://www.metabuilders.com/tools/DefaultButtons.aspx

And here's a good article on the subject:
http://www.allasp.net/enterkey.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"DotNetGruven" <ms********@javagruven.com> wrote in message
news:ur**************@TK2MSFTNGP10.phx.gbl...
Hi,
I have a web form which has:

- Login area with
- email textbox
- password textbox
- <enter> button to log in

- search area with
- string to search for textbox
- <search> button

How can I make this work so that when a user presses <Enter> in:

1) either email or password textbox, I can handle the log in function
which happens on the <enter> button Click() event
2) search textbox, the <search> button Click() event happens

??

TIA,
george

Nov 18 '05 #2
Hi george,
Thank you for using MSDN Newsgroup! My name is Steven, and I'll be
assisting you on this issue.
From your description, you are wanting to set the "default" button for
different entry fields on an ASP.NET web page so that when "enter" key is
pressed with different entry field on focus, different button will be fired
click event?
If there is anything I misunderstood, please feel free to let me know.
Well, I've reviewed the thread and found that Steve has provided serveral
good tech articles on this issue. I believe you may get detailed
information on those articles. And I've also read this one:
http://www.allasp.net/enterkey.aspx

And made a simple test page on this, it does works well. Here is the test
page code, you may try it out yourself to see whether it helps.

-----------------------------------------------aspx page
-----------------------------------
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>PostBack</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
<script language=javascript>
function doLogin()
{
if ((event.which && event.which == 13) || (event.keyCode &&
event.keyCode == 13))
{
document.all("btnLogin").click();return false;
}
else
{
return true;
}
}

function doSearch()
{
if ((event.which && event.which == 13) || (event.keyCode &&
event.keyCode == 13))
{
document.all("btnSearch").click();return false;
}
else
{
return true;
}
}
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<table width="500" align="center">
<tr>
<td><INPUT id="txtLogin" type="text" name="txtPost" runat="server"
onkeydown="doLogin()"></td>
<td><INPUT id="btnLogin" type="button" value="Login" name="btnPost"
runat="server"></td>
</tr>
<tr>
<td><INPUT id="txtSearch" type="text" runat="server"
onkeydown="doSearch()"></td>
<td><INPUT id="btnSearch" type="button" value="Search"
runat="server"></td>
</tr>
</table>
</form>
</body>
</HTML>

----------------------------------------------------------------code-behind
page class -------------------------------------------------------
public class PostBack : System.Web.UI.Page
{
protected System.Web.UI.HtmlControls.HtmlInputText txtLogin;
protected System.Web.UI.HtmlControls.HtmlInputButton btnLogin;
protected System.Web.UI.HtmlControls.HtmlInputButton btnSearch;
protected System.Web.UI.HtmlControls.HtmlInputText txtSearch;

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here

}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.btnLogin.ServerClick += new
System.EventHandler(this.btnLogin_ServerClick);
this.btnSearch.ServerClick += new
System.EventHandler(this.btnSearch_ServerClick);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void btnLogin_ServerClick(object sender, System.EventArgs e)
{
Response.Write("<br>Login is fired at: " +
DateTime.Now.ToLongTimeString());
}

private void btnSearch_ServerClick(object sender, System.EventArgs e)
{
Response.Write("<br>Search is fired at: " +
DateTime.Now.ToLongTimeString());
}
}

--------------------------------------------
If you have any questions or need any further assistance, please feel free
to post here.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #3
The best solution to this is to not use .Net. Just create two forms and
submit them to their respective pages (unless you believe Microsoft and
think that login code should be in the same place as search code).

Jerry

"DotNetGruven" <ms********@javagruven.com> wrote in message
news:ur**************@TK2MSFTNGP10.phx.gbl...
Hi,
I have a web form which has:

- Login area with
- email textbox
- password textbox
- <enter> button to log in

- search area with
- string to search for textbox
- <search> button

How can I make this work so that when a user presses <Enter> in:

1) either email or password textbox, I can handle the log in function
which happens on the <enter> button Click() event
2) search textbox, the <search> button Click() event happens

??

TIA,
george

Nov 18 '05 #4
Thanks all!

The info that I needed was the 3rd link provided by Steve Orr and certainly
was helped by the example provided by Steven Cheng. I was using
<asp:Button>s and that was the rub. The 2nd link was hiding from DNS today!
:)

Not sure what you are trying to say Jerry, but I am required to use and
really dig using .NET! Therefore, I tend to believe what Microsoft says.

More importantly, by boss and the product manager has defined the project
that I'm contracting on to have a login form and a search box, which isn't
unusual these days.

What I found problematic is for the <Enter> key to work when the focus is in
a test field. Do people really do this? I've always hit <Tab> until I get
to the button or use the mouse.

Again, thanks for your help guys,
George

"Jerry III" <je******@hotmail.com> wrote in message
news:uC****************@TK2MSFTNGP12.phx.gbl...
The best solution to this is to not use .Net. Just create two forms and
submit them to their respective pages (unless you believe Microsoft and
think that login code should be in the same place as search code).

Jerry

"DotNetGruven" <ms********@javagruven.com> wrote in message
news:ur**************@TK2MSFTNGP10.phx.gbl...
Hi,
I have a web form which has:

- Login area with
- email textbox
- password textbox
- <enter> button to log in

- search area with
- string to search for textbox
- <search> button

How can I make this work so that when a user presses <Enter> in:

1) either email or password textbox, I can handle the log in function which happens on the <enter> button Click() event
2) search textbox, the <search> button Click() event happens

??

TIA,
george


Nov 18 '05 #5
Hi George,
Thanks for your response. I'm glad that the information is helpful. Also,
If you need any further help, please feel free to post here. I'll be
willing to help you.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Nov 18 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Brett | last post by:
I have a text area form object. A user clicks a send button and the text area information is submitted. How can I also allow the information to be submitted after the user hits the <enter> key? ...
7
by: jerrygarciuh | last post by:
Hello, I have been playing with various Googled solutions for capturing the <Enter> key to suppress form submission. My first question is whether anyone has a script that works in all common...
7
by: Susan Bricker | last post by:
I know that I saw some information concerning the <shift>+<enter> combination use to bypass launching an Access mdb application and enter the Access design workspace. Would someone please direct...
6
by: tor | last post by:
Hello How can I use an other key then TAB to move from one textBox to another?? Torfinn
0
by: VMI | last post by:
If I'm in a multi-line textbox and I'm writing a postal address (ie. write ist line and press <Enter>, write 2nd line and press <Enter>, etc...) how can I make sure that the Enter key will always...
4
by: peshrad | last post by:
Hi ! I'm working with Win 2K and Visual Studio 2003. I have a problem because pressing <ENTER> in a text input control causes a postback of my web form. Here comes some example code (already...
0
by: Tom Edelbrok | last post by:
I'm using VS 2005 to develop an intranet asp.net web application and I get a weird situation. If I start out with any ASPX page that contains an ImageButton control followed by a TextBox control,...
4
by: almurph | last post by:
Hi everyone, I'm a newbie to javascript. I have written some code to detect when a user presses the down-arrow, up-arrow and enter button. Essentially the user can arrow down or up through a...
1
by: almurph | last post by:
Hi everyone, I'm a newbie to vb.net. I have written some code to detect when a user presses the down-arrow, up-arrow and enter button. Essentially the user can arrow down or up through a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.