473,884 Members | 2,415 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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**@createsolu tions.net

Nov 17 '05 #1
6 8232
"Paul Turley" <pa**@createsol utions.net> wrote in message
news:Od******** ******@TK2MSFTN GP11.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**@createsolu tions.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="javas cript">
function testEnterKey()
{
if (event.keyCode == 13)
{
event.cancelBub ble = true;
event.returnVal ue = false;
Form1.Button2.c lick();
}
}
</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(objec t sender, System.EventArg s e)
{
//other initialization code

TextBox1.Attrib utes.Add("onkey press", "testEnterKey() ;");
TextBox2.Attrib utes.Add("onkey press", "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**@createsol utions.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.publi c.dotnet.framew ork.aspnet.webc ontrols,microso ft.public.dotne t
.framework.aspn et
| NNTP-Posting-Host: ts46-03-qdr3731.porch.w a.charter.com 68.113.26.153
| Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP11.phx.g bl
| Xref: cpmsftngxa06.ph x.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1550 03
microsoft.publi c.dotnet.framew ork.aspnet.webc ontrols:12621
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.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**@createsolu tions.net
|
|
|
|

Nov 17 '05 #3
Set the "tab index" to 1
"Jos Branders" <jo************ ***@fastmail.fm > wrote in message
news:3e******** *************@r eader0.news.sky net.be...
"Paul Turley" <pa**@createsol utions.net> wrote in message
news:Od******** ******@TK2MSFTN GP11.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**@createsolu tions.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**@createsolu tions.net
"Tim Boland" <bo*****@email. uc.edu> wrote in message
news:OK******** ******@TK2MSFTN GP10.phx.gbl...
Set the "tab index" to 1
"Jos Branders" <jo************ ***@fastmail.fm > wrote in message
news:3e******** *************@r eader0.news.sky net.be...
"Paul Turley" <pa**@createsol utions.net> wrote in message
news:Od******** ******@TK2MSFTN GP11.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**@createsolu tions.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_Con trol1: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**@createsolu tions.net
"Jos Branders" <jo************ ***@fastmail.fm > wrote in message
news:3e******** *************@r eader0.news.sky net.be...
"Paul Turley" <pa**@createsol utions.net> wrote in message
news:Od******** ******@TK2MSFTN GP11.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**@createsolu tions.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**@createsol utions.net> wrote in message
news:%2******** ********@TK2MSF TNGP10.phx.gbl. ..
The web server button control renders these tags: <input type="submit"
name="Login_Con trol1: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**@createsolu tions.net
"Jos Branders" <jo************ ***@fastmail.fm > wrote in message
news:3e******** *************@r eader0.news.sky net.be...
"Paul Turley" <pa**@createsol utions.net> wrote in message
news:Od******** ******@TK2MSFTN GP11.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**@createsolu tions.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
3637
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
7987
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 close out the form, in which case I can look at the entire set of values and see if they're OK. So, I have this code. for the "Before Update" event: if (their variables are inappropriate) then msgbox "You've entered bad variables (or some...
3
5580
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, and when you press ENTER, this "OK" button's Click event handler is eventually fired. I was expecting Button to have a Default property, but can't seem to find anything like it...
5
3917
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 with the same solution. All had "Default" set in the "Struct Member Alignment" entry. After some assembler debugging we found out that a struct member that is a member function pointer in
8
3527
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 cannot load/unload/reload extensions into my large and slow-to-load application during development without restarting the process then the disadvantages may outweigh the advantages. I've got a mixed-mode program in which I create a new AppDomain...
3
2371
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 advance JB
15
12562
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 property. Where is it? Or mabye change the other thing,No?Thanks ! Simon
1
1707
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
10812
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, and I want it to open with default "a part of field". I did change it to default "A part of the field"? by going to Tools -> Options menu to open the "Options" dialog window. Select the "Edit/Find" tab. Select the "General Search" option button.
0
9954
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9799
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11168
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9591
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7985
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7137
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6009
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4623
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4231
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.