471,326 Members | 2,080 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,326 software developers and data experts.

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 2245
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*********@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.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*********@gmail.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by David Smith | last post: by
5 posts views Thread by Steve S | last post: by
7 posts views Thread by Cemal Karademir | last post: by
2 posts views Thread by Agnes | last post: by
9 posts views Thread by zdrakec | last post: by
8 posts views Thread by Steve K. | last post: by
2 posts views Thread by Jason Huang | last post: by
reply views Thread by rosydwin | last post: by

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.