473,466 Members | 1,349 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Web - Pressing "Return" on a form

Is there a way to specify on each control of a page which button on the
page should be "clicked" when the user presses "return" from within that
control? It seems like it's always just defaulting to the first button
it finds on the page, which isn't always correct.
Regards,
David P. Donahue
dd******@ccs.neu.edu
Nov 16 '05 #1
2 1244
hi david,

Following is what you can do to set the focus to the desired button. It is
necessary to set the focus in the click event
of the button.
I have used RegisterStartupScript to register the javascript. Copy paste the
following code in the webform class and create the controls as necessary.

protected void setTheFocus( System.Web.UI.Control btnControl )
{
string s = "<SCRIPT language='javascript'>document.getElementById('" +
btnControl.ID + "').focus() </SCRIPT>";
this.RegisterStartupScript( "FocusEvent", s );
}

private void Button1_Click(object sender, System.EventArgs e)
{
this.setTheFocus(Button1);
}

private void Button2_Click(object sender, System.EventArgs e)
{
this.setTheFocus(Button2);
}
Happy programming!!!

pradeep_TP

"David P. Donahue" wrote:
Is there a way to specify on each control of a page which button on the
page should be "clicked" when the user presses "return" from within that
control? It seems like it's always just defaulting to the first button
it finds on the page, which isn't always correct.
Regards,
David P. Donahue
dd******@ccs.neu.edu

Nov 16 '05 #2
Here's a control/sample that will solve your problem.

http://scottwater.com/articles/DefaultTextBoxControl

HTH

Dale Preston
MCAD, MCDBA, MCSE
"David P. Donahue" <dd******@ccs.neu.edu> wrote in message
news:uv*************@TK2MSFTNGP14.phx.gbl...
Is there a way to specify on each control of a page which button on the
page should be "clicked" when the user presses "return" from within that
control? It seems like it's always just defaulting to the first button
it finds on the page, which isn't always correct.
Regards,
David P. Donahue
dd******@ccs.neu.edu

Nov 16 '05 #3

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

Similar topics

0
by: Joeyej | last post by:
Hi - I'm trying to move/use a web form (containing some javascript field checks) previously hosted on a Windows 2000 server. However, the FORM METHOD="post..." command in the form (shown below)...
5
by: Lars Netzel | last post by:
Hey! I have tried...(in a datagrid) e.KeyDate.Return and e.KeyDate.TAB end e.KeyDate.Enter
13
by: kurtj | last post by:
Hello Gurus: I have a validation script (below) that is somehow messed up. If the Name field is blank, I get the alert message, then the browser window goes to a blank document with the word...
10
by: Chad | last post by:
Given: #include <stdio.h> #include <stdlib.h> #define MAXLINE 200 int main(void) { char buff;
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
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 ...

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.