473,573 Members | 2,889 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TextBox event handling in C#

Hi Group,

In my C# project there is a 'Search Utility' now, when user type search
key in TextBox and presss enter the 'Search Button' should
automatically get pressed(clicked ) and user should not have to click on
the 'Search button provided' (Similar to any search utility like
google)

I am not getting how to implement it, can somebody help me?

Feb 15 '06 #1
5 2305
if you have multiple <form> elements on the page, the enter keypress
will submit the first <form> on the page. If you want to use enter to
submit a specific button, you need to use javascript on the client side
to capture enter.keypress, then once you catch that event in javascript
you can post whichever form you want to the server manually.

Sorry I don't have any code, but search around on google and you'll
find some info.

Feb 15 '06 #2
Yeah, I have done this on www.northamptonshire.gov.uk.

You will need to view the source code, as I can't remember how I achieved
it. I found the solution on the net though and modified to suit my needs.

Best regards,
Dave Colliver.
http://www.NorthamptonFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available

"Anup" <an*********@gm ail.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
Hi Group,

In my C# project there is a 'Search Utility' now, when user type search
key in TextBox and presss enter the 'Search Button' should
automatically get pressed(clicked ) and user should not have to click on
the 'Search button provided' (Similar to any search utility like
google)

I am not getting how to implement it, can somebody help me?

Feb 15 '06 #3
One route is to hook into the KeyPress event of the textbox, and check for
e.KeyChar being '\r' - if so, simply run the search code (or call
PerformClick() on your existing button).

Does that help?

Marc
Feb 15 '06 #4
Anup,

Is that WebForms or WinForms application?

I kind of suspect you are having WinForms application in mind.

In this case what you can do is to set the form's Accept button to be the
search button. This way you are making latter form's default button, which
in turn means that when the focus is not on one of the other buttons, if
any, and the user presses the Enter key this will be considered as click on
the default button. There are chances that the focused control can swallow
the key event though and this may not work. For example if you have
multiline text box with AcceptsReturn turned on.
--
HTH
Stoitcho Goutsev (100)


"Anup" <an*********@gm ail.com> wrote in message
news:11******** *************@o 13g2000cwo.goog legroups.com...
Hi Group,

In my C# project there is a 'Search Utility' now, when user type search
key in TextBox and presss enter the 'Search Button' should
automatically get pressed(clicked ) and user should not have to click on
the 'Search button provided' (Similar to any search utility like
google)

I am not getting how to implement it, can somebody help me?

Feb 15 '06 #5
Mine is a web form and there is no keypress event for Text box in
WebControls, I think I have to use Javascript to do this, but i m still
not getting the perfect way..

Feb 23 '06 #6

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

Similar topics

1
4261
by: David Smith | last post by:
What I want to be able to do: A textbox is available that the user can enter information into. Specifically (for the purposes of this post), the user is asked to enter a number, and that number has an upper limit. I want to do validation on what the user enters as they type it in. I set up an event handler for KeyPress that restricts...
4
20595
by: Alpha | last post by:
Hi, I have a window based applicaton. I want to make sure that the users enter integer numbers before I save it to the database. I know to code this in the textbox_validating event but I don't know what function to call to make sure the input are all integer nubmers. Thanks, Alpha
5
2475
by: Steve S | last post by:
Heres what I want to do...User types into a texbox, clicks a button, the button saves that text to a file. The problem is that when I click the submit button, any changes made to the textbox are lost, and it reloads what was previously there. Any ideas? try {
7
3434
by: Cemal Karademir | last post by:
Hello, Please forgive my simple question, but i don't know the correct synatx. From the masterpage i want to put a text in an textbox and then select an item in the datagrid. I do know how to pass the items in the datagrid(e.g. PLU, description, etc.) to an other (detail)page, but i don't know the correct syntax of how to pass the textbox...
7
3071
by: Itar | last post by:
I'm having a problem supressing characters in a text box. I only want alpha numeric characters (no special chars). I can handle the TextBox_KeyPress event to supress the invalid characters when the user types them in, however that doesn't handle the user pasting invalid characters. I thought to use the MouseDown event but I couldn't figure...
2
2361
by: Agnes | last post by:
When the textbox 's Enabled = True, (its backcolor is white) When the Textbox got focus (backcolor change to pink by my code) when the textbox lost focus(back color change to white by my code) NOw. the problem is "When textbox 's Enabled = false. ( the back color still white but not gray) Does anyone know how to solve this problem ?? thanks...
14
14587
by: teddysnips | last post by:
WINDOWS FORMS I've a form that has a textbox that allows the user to enter a string. On the LostFocus event, the textbox formats the string into a preferred format. However, if the user presses the "Save" button while the textbox has the focus, the LostFocus code doesn't run at the right time, so that the "Save" function is dealing with...
9
3210
by: zdrakec | last post by:
Hello all: Clearly, I'm not getting it! Here is the scenario: On a web page, I have two list boxen and a text box. The first listbox is populated at page load time (if it is not a postback). This listbox has AutoPostback = True. When the user selects an item from this list, the second listbox is populated with more items relevant to this...
8
7705
by: Steve K. | last post by:
I want to have AutoSuggest based on a database (or webservice) query. So as the user types say... a last name I will make an async call to a service to get matches, then set the suggestion list at runtime. I tried this quick by handling the key down event and building a "dumb" Suggestion list and assigning to the TextBox control but it seem...
2
6247
by: Jason Huang | last post by:
Hi, How do I override a TextBox's KeyPress evnt? And how do we use it? Thanks for help. Jason
0
7704
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...
0
8031
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. ...
0
8204
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...
1
7795
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...
0
5294
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...
0
3735
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2223
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
1
1309
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1044
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.