473,394 Members | 1,766 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,394 software developers and data experts.

Make button "default"

Does anyone have some sample script to "press" a button or image button when
the user presses the Enter key? I see this behavior on a lot of web pages
but I'm not finding any samples.

Thx

--
Paul Turley, MCSD, MCAD, MCT, MSF Practitioner, A+ Technician
pa**@createsolutions.net

Nov 17 '05 #1
6 8209
"Paul Turley" <pa**@createsolutions.net> wrote in message
news:Od**************@TK2MSFTNGP11.phx.gbl...
Does anyone have some sample script to "press" a button or image button when the user presses the Enter key? I see this behavior on a lot of web pages
but I'm not finding any samples.

Thx

--
Paul Turley, MCSD, MCAD, MCT, MSF Practitioner, A+ Technician
pa**@createsolutions.net


Just use the HTML tag <input type="submit" value="click here or press
enter">

--

Jos Branders
Nov 17 '05 #2
Hi Paul,

In case you have multiple buttons on a webform, you could try this method.

When a webform contains multiple buttons, the first one rendered will be
fired when you press the Enter button. However, we can workaround this
problem using the
following method:

1. Add the following script code to the <head> section of the aspx page.

<SCRIPT LANGUAGE="javascript">
function testEnterKey()
{
if (event.keyCode == 13)
{
event.cancelBubble = true;
event.returnValue = false;
Form1.Button2.click();
}
}
</SCRIPT>

2. In the code-behind page, add the onkeypress event handler to the
attributes collectioins of the TextBox(es) on the page:

private void Page_Load(object sender, System.EventArgs e)
{
//other initialization code

TextBox1.Attributes.Add("onkeypress", "testEnterKey();");
TextBox2.Attributes.Add("onkeypress", "testEnterKey();");
......
}

More information:

HOWTO: Prevent Form Submission When User Presses the ENTER Key on a Form
(Q298498)
http://support.microsoft.com/support.../Q298/4/98.ASP

returnValue Property
http://msdn.microsoft.com/workshop/a...erties/returnv
alue_1.asp

cancelBubble Property
http://msdn.microsoft.com/workshop/a...erties/cancelb
ubble.asp

Regards,

Felix Wu
=============
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| From: "Paul Turley" <pa**@createsolutions.net>
| Subject: Make button "default"
| Date: Wed, 25 Jun 2003 22:08:00 -0700
| Lines: 12
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.3790.0
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Message-ID: <Od**************@TK2MSFTNGP11.phx.gbl>
| Newsgroups:
microsoft.public.dotnet.framework.aspnet.webcontro ls,microsoft.public.dotnet
.framework.aspnet
| NNTP-Posting-Host: ts46-03-qdr3731.porch.wa.charter.com 68.113.26.153
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.aspnet:155003
microsoft.public.dotnet.framework.aspnet.webcontro ls:12621
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Does anyone have some sample script to "press" a button or image button
when
| the user presses the Enter key? I see this behavior on a lot of web pages
| but I'm not finding any samples.
|
| Thx
|
| --
| Paul Turley, MCSD, MCAD, MCT, MSF Practitioner, A+ Technician
| pa**@createsolutions.net
|
|
|
|

Nov 17 '05 #3
Set the "tab index" to 1
"Jos Branders" <jo***************@fastmail.fm> wrote in message
news:3e*********************@reader0.news.skynet.b e...
"Paul Turley" <pa**@createsolutions.net> wrote in message
news:Od**************@TK2MSFTNGP11.phx.gbl...
Does anyone have some sample script to "press" a button or image button

when
the user presses the Enter key? I see this behavior on a lot of web pages but I'm not finding any samples.

Thx

--
Paul Turley, MCSD, MCAD, MCT, MSF Practitioner, A+ Technician
pa**@createsolutions.net


Just use the HTML tag <input type="submit" value="click here or press
enter">

--

Jos Branders

Nov 17 '05 #4
I've tried this. I'm setting the tab index of my web server button to 1 and
I've set it to the next index in sequence for all the controls. In either
case, pressing Enter does nothing. This is on a web user control. I think
I need to use client-side script to capture the Enter key press - unless I'm
missing something.

--
Paul Turley, MCSD, MCAD, MCT, MSF Practitioner, A+ Technician
pa**@createsolutions.net
"Tim Boland" <bo*****@email.uc.edu> wrote in message
news:OK**************@TK2MSFTNGP10.phx.gbl...
Set the "tab index" to 1
"Jos Branders" <jo***************@fastmail.fm> wrote in message
news:3e*********************@reader0.news.skynet.b e...
"Paul Turley" <pa**@createsolutions.net> wrote in message
news:Od**************@TK2MSFTNGP11.phx.gbl...
Does anyone have some sample script to "press" a button or image
button
when
the user presses the Enter key? I see this behavior on a lot of web

pages but I'm not finding any samples.

Thx

--
Paul Turley, MCSD, MCAD, MCT, MSF Practitioner, A+ Technician
pa**@createsolutions.net


Just use the HTML tag <input type="submit" value="click here or press
enter">

--

Jos Branders


Nov 17 '05 #5
The web server button control renders these tags: <input type="submit"
name="Login_Control1:btnLogin" ...

I am calling server-side code on the click event so I need to use a web
server button or image button.

I've set the tab index to 0, 1 and other values. Any ideas?

--
Paul Turley, MCSD, MCAD, MCT, MSF Practitioner, A+ Technician
pa**@createsolutions.net
"Jos Branders" <jo***************@fastmail.fm> wrote in message
news:3e*********************@reader0.news.skynet.b e...
"Paul Turley" <pa**@createsolutions.net> wrote in message
news:Od**************@TK2MSFTNGP11.phx.gbl...
Does anyone have some sample script to "press" a button or image button

when
the user presses the Enter key? I see this behavior on a lot of web pages but I'm not finding any samples.

Thx

--
Paul Turley, MCSD, MCAD, MCT, MSF Practitioner, A+ Technician
pa**@createsolutions.net


Just use the HTML tag <input type="submit" value="click here or press
enter">

--

Jos Branders

Nov 17 '05 #6

I used this script for component asp:button but it didn't work. Than I
changed the component with asp:imagebutton (also added gif image for button)
and used this script. Now it works right.

<input type="text" onkeypress="if (event.keyCode == 13) return false"
runat="server">

lep pozdrav, Jure

"Paul Turley" <pa**@createsolutions.net> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
The web server button control renders these tags: <input type="submit"
name="Login_Control1:btnLogin" ...

I am calling server-side code on the click event so I need to use a web
server button or image button.

I've set the tab index to 0, 1 and other values. Any ideas?

--
Paul Turley, MCSD, MCAD, MCT, MSF Practitioner, A+ Technician
pa**@createsolutions.net
"Jos Branders" <jo***************@fastmail.fm> wrote in message
news:3e*********************@reader0.news.skynet.b e...
"Paul Turley" <pa**@createsolutions.net> wrote in message
news:Od**************@TK2MSFTNGP11.phx.gbl...
Does anyone have some sample script to "press" a button or image
button
when
the user presses the Enter key? I see this behavior on a lot of web

pages but I'm not finding any samples.

Thx

--
Paul Turley, MCSD, MCAD, MCT, MSF Practitioner, A+ Technician
pa**@createsolutions.net


Just use the HTML tag <input type="submit" value="click here or press
enter">

--

Jos Branders


Nov 17 '05 #7

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

Similar topics

2
by: AA Arens | last post by:
When I place a record serch utility (vos the button placement wizzrd), I discovered that the Match setting is "Whole Field" by default. How to make "Any Part Of Field" default?
2
by: Paul Brady | last post by:
I have non-computer skilled users entering data into a form. There are certain ranges of values which, if they enter them, make no sense in the application, but I can't test them until they try to...
3
by: C# Learner | last post by:
Is it possible to set a command button to the "default" button of the form? Here's an example of what I mean -- press Start -> Run. Notice that the "OK" button has a dark rectangle around it,...
5
by: Hendrik Schober | last post by:
Hi, we just run into the problem, that "default" alignment in the project properies dialog seem to be different. We have a project that's a DLL, which is linked with a couple of LIBs. All are...
8
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this? Mixed-mode is incredibly convenient, but if I...
3
by: Jensen bredal | last post by:
Hello, I have an html submit button wich i have converted into a server control(ascx) . I want it serverside click event to be fired on "enter". How can this be achieved? Many thanks in...
15
by: simonoficina | last post by:
Hello all! I am a vb.net beginner in Spain. When I use VB6 ,the button object has a property called "default" that can set this button like press "ENTER" key. But in the VB.net I can't find this...
1
by: test | last post by:
Using a DetailsView to update data in SQL 2005, How do I change the default "Update" hyperlink to a more user friendly button? Thanks
10
Shakss2
by: Shakss2 | last post by:
I have a form, where I can activate the search and replace dialogbox when pressing a button. My problem is that the dialogbox opens with the default that it should search for full match only,...
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:
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.