By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,916 Members | 1,078 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,916 IT Pros & Developers. It's quick & easy.

Default Button Click On Enter KeyPress On Web Form

P: n/a
I have an asp.net 1.1/C# web form with a text box server control and
one button server control. Users can type in text to search and then
click the button to start the search. I want them to be able to type
in text and then just hit the Enter key instead of having to click the
button.

Currently, an Enter keypress causes a post back, but it does not fire
the event handler for the button click. How can I get this to work?

Feb 28 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Not sure if this is "right", but what I do is do the update in the load
event; but only if the cancel button hasn't been clicked;

if (Page.IsPostback)
{
if (Request.Form["cmdCancel"] != null)
return;

// Save the data
}

So pressing [enter] will trigger a postback that will save, as will pressing
your submit button. Pressing the cancel button causes the postback but the
update code is not run.

Would be interested if someone has a "proper" way.

"Joey" <jo*********@topscene.comwrote in message
news:11**********************@a75g2000cwd.googlegr oups.com...
>I have an asp.net 1.1/C# web form with a text box server control and
one button server control. Users can type in text to search and then
click the button to start the search. I want them to be able to type
in text and then just hit the Enter key instead of having to click the
button.

Currently, an Enter keypress causes a post back, but it does not fire
the event handler for the button click. How can I get this to work?

Feb 28 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.