473,795 Members | 2,983 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

disable enterkey in a form

Hi,
How can I disable enterkey in a form. I have using couple of asp textboxes,
one asp button for search and two Image Buttons, one for Back[will come
first] and other for continue[will come next]. But If I click on the text
box and perss enter key it will always execute the back Image button and the
page is redirecting to the previous page. I gave last tab order index for
this button , it didn't work. I just want execute the search button if they
click enter. How could i do this. Could any one can put some light on it.

Thanks in Advance

John

Nov 18 '05 #1
1 2373
Try using some javascript.
I added it to my Base page that I inherit from and inject it to each child
page.
(As a bonus you get to set the initial focus for any control)

=============== =============== =============== =============== ==========
Add code like this to any child page where you want to set focus to a
control or kill the enter key:

Public Sub New()
MyBase.New()

'set the focus to the UserID text box:
InitialFocus = txtUserId

'Do Not kill the Enter key on this page
Me.killEnterKey = False

'Kill the Enter key on this page
'Me.killEnterKe y = True

End Sub

=============== =============== =============== =============== ==========
Add this code to your javascript library which is loaded for each page:

function NetscapeEventHa ndler_KeyDown(e ) {
if (e.which == 13 && e.target.type != 'textarea' && e.target.type !=
'submit') { return false; }
return true;
}

function MicrosoftEventH andler_KeyDown( ) {
if (event.keyCode == 13 && event.srcElemen t.type != 'textarea' &&
event.srcElemen t.type != 'submit')
return false;
return true;
}

=============== =============== =============== =============== ==========
Add this to the top of your Base page:

Public InitialFocus As Control
Protected KillEnterKey As Boolean = True

=============== =============== =============== =============== ==========
Protected Overridable Sub Page_PreRender( ByVal sender As Object, ByVal e As
EventArgs)

Dim sb As New StringBuilder

'-- Focus
sb.Append("<scr ipt language='javas cript'>")
If Not InitialFocus Is Nothing Then
sb.Append("docu ment.getElement ById('" & InitialFocus.Cl ientID &
"').focus() ;")
End If

'-- Append to the Browser Title set on an instance level

'Code to call the Enter button kill javascript in library
If KillEnterKey = True Then
sb.Append("var nav = window.Event ? true : false;")
sb.Append("if (nav) {")
sb.Append("wind ow.captureEvent s(Event.KEYDOWN );")
sb.Append("wind ow.onkeydown = NetscapeEventHa ndler_KeyDown;" )
sb.Append("} else {")
sb.Append("docu ment.onkeydown = MicrosoftEventH andler_KeyDown; ")
sb.Append("}")
End If

sb.Append("</script>")
RegisterStartup Script("My JScript", sb.ToString())

End Sub

=============== =============== =============== =============== ==========
--
Joe Fallon

"John Smith" <Jo**@nospam.ya hoo.com> wrote in message
news:ue******** ******@TK2MSFTN GP10.phx.gbl...
Hi,
How can I disable enterkey in a form. I have using couple of asp
textboxes,
one asp button for search and two Image Buttons, one for Back[will come
first] and other for continue[will come next]. But If I click on the text
box and perss enter key it will always execute the back Image button and
the
page is redirecting to the previous page. I gave last tab order index for
this button , it didn't work. I just want execute the search button if
they
click enter. How could i do this. Could any one can put some light on it.

Thanks in Advance

John

Nov 18 '05 #2

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

Similar topics

2
1529
by: Bruno Alexandre | last post by:
Hi guys, If I want to block a user to change a form after submiting, I add a function that will disable the submit button, but when I'm getting the form collection (using post or get (form/querystring) I can't retrieve that button value... Is there any trick to do this? Like https://www.cuworld.com/ webpage... Try to register as a free user membership and after click the submit button check what hapend... They
5
5985
by: Bob Bedford | last post by:
I create checkboxes using datas from a database (with PHP). I store all values in an array, as I must pass this value like a Form value. Now, in some cases, when a checkbox is selected, I must disactivate other checkboxes. How can I do this ? here is the code:
12
8885
by: Forti2ude | last post by:
Hello, I have a simple form... <form> <select name="foo" multiple> <option value="1">one</option> <option value="2">two</option> <option value="3">three</option> </select>
2
2728
by: cw | last post by:
Hi group, My page consist of few text boxes and a server side button control (asp:button), when i finished editing and press enter key, it will fire up the button click event. How to disable this event till i click or focus to the button? regards,
2
2950
by: nicholas | last post by:
How can I disable the enter key on an asp.net page? As the default button is the first on the page, and as the enter key clicks the default button, and as my first button on the page is th 'logou' button => when I have a search form for example and my users press ENTER instead of clicking on the button, they are logged out instead of transferred to the search results. So, I would like to disable the ENTER key...unless sombody has a...
4
3126
by: Chris | last post by:
I have an asp.net page say page1.aspx. The form in html code is <form id = "Form1"> And i want to disable all the fields of the form after some code steps. I had created a javascript funct: function disable() { alert("Forms length is :" + Form1.length); for (i = 0; i < Form1.length; i++) { var formElement = Form1.elements;
0
1806
by: Ahmad Jalil Qarshi | last post by:
Hi! I have a problem while developing some webpages.The Problem is that:- How We Can Disable The Controls Of One Web Form From Other Web Form In Asp.net? Explanation:- There Should Be Two Web Form,Web Form1.aspx and Web Form2.aspx,Now From Web Form1.aspx When I Click One Button (Disable), Then Web Form2.aspx Buttons
1
1194
by: Miro | last post by:
VB.net 2005 Express Say I have Dim MyString as String = "ABCDEF" and currently I have a timer that sends every 5 seconds: SendKeys.Send( MyString )
1
1138
by: ahmadnadeem | last post by:
hi Dear, i have aproblem in richtextbox.the problem is when i press the enterkey four times then the cursor should come to the next line within the rich textbox. please tell me about the event which is used in this case and the code. thanks
0
9672
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
10438
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
10214
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9042
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...
0
6780
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
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3727
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.