Default Button Click On Enter KeyPress On Web Form

J

Joey

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?
 
A

Aidy

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top