ENTER and forms

  • Thread starter Thread starter news
  • Start date Start date
N

news

Can I use ENTER to submit my form using C#?

I have used
Page.RegisterHiddenField("__EVENTTARGET", "btnFind");



This works SOMETIMES but not all the time.



I saw



http://msdn.microsoft.com/library/d...systemwindowsformsformclassactivatedtopic.asp



and
http://msdn.microsoft.com/library/d...stemwindowsformscontrolclassgotfocustopic.asp



which explains that ENTER is not used since the Activate is used for Forms.
I understand the logic but I still cant get my forms to always submit on
ENTER and instead it uses the first control (a list) and ends up being
redirected.



Enter has been used for decades to submit a request dating back to "dumb
terminals" and even typewriters. So it makes sense to use the ENTER to
submit forms.
 
Hi,

As far as ASP .NET forms are concerned (the MSDN article you're referring to
speaks about Windows Forms which are quite a different technology having
nothing to do with Web programming), there is a special type of the <INPUT>
control - <INPUT TYPE="Submit">. This control corresponds to the
System.Web.UI.WebControls.Button control in ASP .NET. Just make sure not to
define the CommandName and OnCommand properties on the Web form for the
button control to be rendered as the submit and not a command button.
 
Back
Top