I have a text box and a button, and I want the enter key to run the click
event of the button. The textbox and button are inside a user control. I
tried all sorts of stuff with the __EVENTTARGET hidden field with no luck.
Here's what I'm doing
function KeyDownHandler( btn)
{
if (event.keyCode == 13)
{
event.returnVal ue=false;
event.cancel = true;
btn.click();
}
}
<asp:TextBox ID="txtNewsFeed Name" Runat="server" MaxLength="100"
Columns="35" onKeyDown="KeyD ownHandler('btn CreateNewsFeed' )"></asp:TextBox>
<asp:button ID="btnCreateNe wsFeed" Runat="server" Text="Add"
CssClass="submi tbutton" CausesValidatio n="False"></asp:button>
When I hit Enter when typing inside the TextBox, the KeyDownHandler function
gets executed, but I get an error on the btn.click(); line.
The error is: object doesn't support this property or method.
Verified that btn is coming in as btnCreateNewsFe ed. Dunno if you need to do
casting in JavaScript, but how is this function supposed to know that this
is a button...
How can fire the click event of that button? 2 14660
Think about the value you pass to the function. You are passing the ID of
the btn, so you can't just call btn.click(); - that's the same as saying
'btnCreateNewsF eed'.click() and that will not work.
Instead, replace btn.click(); with document.getEle mentById(btn).c lick();
"George Durzi" <gd****@hotmail .com> wrote in message
news:eD******** ******@TK2MSFTN GP09.phx.gbl... I have a text box and a button, and I want the enter key to run the click event of the button. The textbox and button are inside a user control. I tried all sorts of stuff with the __EVENTTARGET hidden field with no luck.
Here's what I'm doing
function KeyDownHandler( btn) { if (event.keyCode == 13) { event.returnVal ue=false; event.cancel = true; btn.click(); } }
<asp:TextBox ID="txtNewsFeed Name" Runat="server" MaxLength="100" Columns="35"
onKeyDown="KeyD ownHandler('btn CreateNewsFeed' )"></asp:TextBox> <asp:button ID="btnCreateNe wsFeed" Runat="server" Text="Add" CssClass="submi tbutton" CausesValidatio n="False"></asp:button> When I hit Enter when typing inside the TextBox, the KeyDownHandler
function gets executed, but I get an error on the btn.click(); line.
The error is: object doesn't support this property or method.
Verified that btn is coming in as btnCreateNewsFe ed. Dunno if you need to
do casting in JavaScript, but how is this function supposed to know that this is a button...
How can fire the click event of that button?
That's a great solution, thank you
"hb" <hb************ ****@merc.merce r.edu> wrote in message
news:2h******** ****@uni-berlin.de... "George Durzi" <gd****@hotmail .com> wrote in message news:O$******** ******@TK2MSFTN GP11.phx.gbl... As I mentioned, by textbox and button are in a user control,
So I actually have to do KeyDownHandler( 'usercontrolnam e:btnCreateNews Feed') since that's how the element is being rendered.
And of course, as you suggested, with the document.getEle mentById(btn).c lick();
It now works
Thank you
Glad you figured out the ID - I thought about that after I posted my reply but hoped you would realize the solution.
I usually make sure the Button's Client ID is always correct by assigning the onKeyDown event in code-behind, like this:
textBox.Attribu tes.Add("onKeyD own", "KeyDownHandler ('" + btn.ClientID + "')");
Why? Because 'usercontrolnam e:btnCreateNews Feed' doesn't apply if you for any reason add the control dynamically, because then it is something like '_ctl2:btnCreat eNewsFeed'.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Ali Eghtebas |
last post by:
Hi,
I have 3 questions regarding the code below:
1) Why can't I trap the KEYDOWN while I can trap KEYUP?
2) Is it correct that I use Return True within the IF-Statement? (I've
already read the documentation but it is rather hard to understand so please
don't refer to it :)
3) Many examples in the newsgroups use Return MyBase.ProcessKeyPreview(m) as
the last code line while I have used Return MyBase.ProcessKeyEventArgs(m)
|
by: SpinningCone |
last post by:
Im currently building a MUD telnet client in VB .NET and am having trouble
mapping functionality to certain keys.
the user is focused on a command textbox and can enter text and send it etc
etc but i also want the arrow keys and the numberpad to have special
functions.
now generally i like the keydown event because it has access to e.keycode
which will give me easy acces to capture any key on the board. keycode also
differentiates the...
|
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
browsers? The script bellow is IE only. It fails FF 1.0 and NN 7.
Also, if I can trap the keypress I would like to use it to tab to the next
tabindex.
|
by: msnews.microsoft.com |
last post by:
How can I disable a beep when I press Enter on TexBox
I'm trying this but it don't work:
I do it in KeyDown event
If e.KeyCode = Windows.Forms.Keys.Enter Then
' Do something ...
e.Handled = True
End If
|
by: Chris Wertman |
last post by:
This seems like a simple one, ive searched the msdn and groups and cant
come up with the answer however.
I dont build gui apps very often (actually this is my first in oh 3
years)
I have a form and a textbox
When I put text in it and press enter I want it to DO SOMETHING, but I
cant find what event that is. When I press enter I just get the dink
| |
by: Adam J. Schaff |
last post by:
I have noticed that if a user closes a form via pressing return (either
while the OK button has focus or if AcceptButton is set to OK for the form)
then the "ENTER" keypress event fires ON THE CALLING FORM! This is very bad
for me, because in my application, Form1 responds to an ENTER keypress by
calling Form2. If the user closes Form2 via an ENTER, then Form1 just
reopens it again, kind of trapping the user in Form2 (they can still close...
|
by: senfo |
last post by:
Hello all,
To help alleviate human error, I'm developing an application that uses a
barcode reader to fill in a value in a TextBox control. The barcode
reader is connected to the PC through the PS2 keyboard jack, so to
Windows, it's essentially just a keyboard. After the reader has
finished reading the barcode, it sends out Ctrl + M (which I *think* is
a carriage return).
To capture the Ctrl + M, I configured an event handler for the
|
by: kgerritsen |
last post by:
I am building an application that will receive input from a barcode
scanner. The barcode scanner is configured to append to the front
value a single character and hyphen that identify the barcode
standard, then the value in the barcode, terminated by a return. The
barcode scanner appears to the operating system as a USB keyboard.
I am loading the barcode value into a textbox both on my Form1 and on
a dialog box where the user has to...
|
by: jagwinderwalia |
last post by:
Hi all
i have build a autocomplete textbox control that works on keyup event in javascript. everytime a keyup is called , a request is send back to server and the suggestion are displayed in div below the textbox.
when enter is pressed,selected value comes in textbox. Now the problem is when i pressed enter button event is called. and the list disapears.
To solve this i set it to on keydown event. but the keydown is called twice, i dont...
|
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...
|
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,...
| |
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...
|
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...
|
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,...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |