Can't use enter on asp.net form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a web form with a listbox and single text box and a single button.
When my users type in the text box and press enter, it doesn't submit. It
refreshes the page and clears the textbox.

Any ideas?
 
yeah submit is done by onclick of a button or a hyperlink. enter doesnt do
the job (as event args need to be populated with right info so what happens
is it just does a page_load and comes back) and what i tend to do is disable
it altogether.

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
 
Hi Mark,

Hermit's suggstion is reasonable. The ASP.NET webform need some control to
fire the post back event and not all the controls can fire such event by
default. The "submit button" , "link button" 's click can by default make
the page post back to server. So you need to add a button on the web form
page to let the user post back the page.

In addition, here are some referernce in MSDN on the asp.net's page model
and control events:

#Introduction to ASP.NET and Web Forms
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
ml/introwebforms.asp

#Events in ASP.NET Server Controls
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconeventsinwebformscontrols.asp

Hope helps.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
I have a button. But many users are used to pressing the enter key after
keying in a password.
 
Hi Mark,

Thanks for the followup. Based on your further description, I think this is
a normal behavior of the web page. The asp.net page didn't have the
"default button" feature(which exist in windows form application) by
default.

As for how to make a Button control as the default button on a asp.net
webform page, there is no buildin means for setting default button. We can
use javascript code to let a certain button be clicked when we press
"enter" key on a textbox. Here are some tech articles and former threads
discussing on the same question:


http://www.kamp-hansen.dk/pages/showdoc.asp?id=28&menuid=21&menuid=18

http://www.metabuilders.com/tools/DefaultButtons.aspx

http://www.allasp.net/enterkey.aspx


http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=CyvtFHT8DHA.1152%
40cpmsftngxa07.phx.gbl&rnum=1&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26
q%3Denter%2Bkey%2Bsteven%2Bcheng

Hope helps. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

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

Back
Top