473,216 Members | 1,285 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to do a post back when user press enter.

In a regular html form, when user press "enter" key, the form will be
submitted.

However, in ASP.NET web form, a form will only be submitted (post back) when
a special button is clicked. Many user get used to click "enter" key to
submit a form. How can I use "enter" key to submit/postback in ASP.NET.

Thank,

Guoqi Zheng
http://www.ureader.com
Nov 19 '05 #1
6 3711
Either you use javascript functionality to do document.myform.submit() or
you let the user press enter twice,
so that he gets onto submit-button on pressing enter in input-field.

Am Sun, 29 May 2005 14:56:14 +0200 schrieb <"guoqi zheng"<no@sorry.com>>:
In a regular html form, when user press "enter" key, the form will be
submitted.

However, in ASP.NET web form, a form will only be submitted (post back)
when
a special button is clicked. Many user get used to click "enter" key to
submit a form. How can I use "enter" key to submit/postback in ASP.NET.

Thank,

Guoqi Zheng
http://www.ureader.com


--
Erstellt mit Operas revolutionärem E-Mail-Modul: http://www.opera.com/mail/
Nov 19 '05 #2
Hi Guoqi,

You need to understand the ASP.Net object model more clearly. Let me see if
I can explain it to you so that you understand a bit better.

First, remember that ASP.Net lives and works in the same enviornment as any
web site does. It is hosted on a web server, with pages that are requested
by a client browser, served up via HTTP. The pages are generated by an ISAPI
(Internet Server Application Programming Interface) application on the
server, which is ASP.Net, but they are still HTML documents when they reach
the client browser, which is designed to read and interpret HTML.

So, the rules of HTML still apply on the client, and the page behaves just
as any other HTML page would behave in a browser. The transport protocol is
still HTTP, so the same rules and environment of HTTP still apply. This
means that, as HTTP is stateless, each Request/Response happens "in a
vacuum" so to speak. That is, the client fires a request to the web server,
and the web server fires (and forgets) a Response to the client. An HTML
page is an isolated instance of a browser window, with no memory of anything
previous, other than the built-in browser memory for such things as the
Referer (last page URL requested) and the history (a list of URLs visited).

ASP.Net is a server-side object-oriented event-driven programming model.
Now, as HTTP is stateless, how are events going to be processed on the
server, which doesn't even remember what page URL the client last Requested,
or anything about that page? In a Windows application, which has persistent
memory, an event is fired by an application, and the event handler IN that
application responds via the application, making changes to its process and
UI, via the event handler. So, the first obstacle to overcome is how to have
an event occur in a client HTML page, be transmitted back to the server, and
have the server respond to the event while "updating" the very same HTML
page (which is actually an entirely new instance of that page)?

The answer is, the page is a form (a WebForm) which posts to its own URL (as
diffeentiated from "itself" which is of course, impossible, since it is on
the client, not the server), resulting in a new instance of the same page in
the browser. The PostBack data is simply HTML form data containing
information about the current state of the page on the client (in the
browser). Thus we have the ASP.Net WebForm PostBack event model.

By now you should see that, as the page on the client is simply an HTML
form, pressing the ENTER key would indeed submit the page back to its own
URL. So, you're first assumption ("in ASP.NET web form, a form will only be
submitted (post back) when a special button is clicked") is wrong. In fact,
we get questions almost daily about how to PREVENT an ASP.Net page from
posting back when the ENTER key is pressed.

What you may be mixing up is in regards to the event model I described. In
order for the server to handle an event from a specific Control (form
element on the client HTML document), the server must know which Control
(form element on the client HTML document) was in fact clicked (or changed).
This brings us to the second element of the ASP.Net event model, which is
how to tell which Control caused the event.

Again, we're talking about a plain vanilla HTML document on the client side.
So, how does an HTML form tell the server anything? It does so via the form
fields whose values are posted back to the form handler. Now, how would an
HTML form send information about a client-side event to the server in its
form values collection? First, you would need a client-side event handler.
This is available through JavaScript (an "onclick" event handler in
JavaScript, for example, or an "onchange" event handler for something like a
drop-down list box). Second, you would need a hidden form field that the
JavaScript can put a value into. In fact, ASP.Net automatically generates
such JavaScript and the appropriate form fields when you insert a Control
into an ASP.Net page.

So, the user clicks a button. The "onclick" JavaScript event-handler for
that button is fired, which then puts the ID of the button into one hidden
form field, and the value of the button into another hidden form field. The
value isn't important with a button, but, for a textbox, for example, the
value is important. The form is posted back to the same Page class on the
server (via its URL being the same), which then reads the form field values,
and rebuilds the page according to your custom Event Handler methods in that
Page class. Then it returns a modified version of the same HTML document to
the client, which starts the whole process all over again.

There is a lot more to it than that, but hopefully the appetizer will whet
your appetite.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"guoqi zheng" <no@sorry.com> wrote in message
news:72******************************@ureader.com. ..
In a regular html form, when user press "enter" key, the form will be
submitted.

However, in ASP.NET web form, a form will only be submitted (post back)
when
a special button is clicked. Many user get used to click "enter" key to
submit a form. How can I use "enter" key to submit/postback in ASP.NET.

Thank,

Guoqi Zheng
http://www.ureader.com

Nov 19 '05 #3
Guoqi,

"Enter" key functionality of a regular html form is achieved by using an
<input type=submit> control. Nothing stops you from using the same control
in an aspx form:

<input type="submit" value="Submit">

If you want it to be a server control or/and to generate a server-side
onclick event, add attributes runat=server and OnServerClick="MyHandler"

Eliyahu

"guoqi zheng" <no@sorry.com> wrote in message
news:72******************************@ureader.com. ..
In a regular html form, when user press "enter" key, the form will be
submitted.

However, in ASP.NET web form, a form will only be submitted (post back) when a special button is clicked. Many user get used to click "enter" key to
submit a form. How can I use "enter" key to submit/postback in ASP.NET.

Thank,

Guoqi Zheng
http://www.ureader.com

Nov 19 '05 #4
PB
Kevin,

I just wanted to take a second to thank you for your great explanations;
not only to the OP here, but your responses in general.

You don't have to offer these great insights and "birds eye" views of
ASP.NET, but you do, and it has been incredibly helpful. Your answers
prevent many other questions from having to be asked... definitely "MVP
stuff."

-PB
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
Hi Guoqi,

You need to understand the ASP.Net object model more clearly. Let me see
if I can explain it to you so that you understand a bit better.

First, remember that ASP.Net lives and works in the same enviornment as
any web site does. It is hosted on a web server, with pages that are
requested by a client browser, served up via HTTP. The pages are generated
by an ISAPI (Internet Server Application Programming Interface)
application on the server, which is ASP.Net, but they are still HTML
documents when they reach the client browser, which is designed to read
and interpret HTML.

So, the rules of HTML still apply on the client, and the page behaves just
as any other HTML page would behave in a browser. The transport protocol
is still HTTP, so the same rules and environment of HTTP still apply. This
means that, as HTTP is stateless, each Request/Response happens "in a
vacuum" so to speak. That is, the client fires a request to the web
server, and the web server fires (and forgets) a Response to the client.
An HTML page is an isolated instance of a browser window, with no memory
of anything previous, other than the built-in browser memory for such
things as the Referer (last page URL requested) and the history (a list of
URLs visited).

ASP.Net is a server-side object-oriented event-driven programming model.
Now, as HTTP is stateless, how are events going to be processed on the
server, which doesn't even remember what page URL the client last
Requested, or anything about that page? In a Windows application, which
has persistent memory, an event is fired by an application, and the event
handler IN that application responds via the application, making changes
to its process and UI, via the event handler. So, the first obstacle to
overcome is how to have an event occur in a client HTML page, be
transmitted back to the server, and have the server respond to the event
while "updating" the very same HTML page (which is actually an entirely
new instance of that page)?

The answer is, the page is a form (a WebForm) which posts to its own URL
(as diffeentiated from "itself" which is of course, impossible, since it
is on the client, not the server), resulting in a new instance of the same
page in the browser. The PostBack data is simply HTML form data containing
information about the current state of the page on the client (in the
browser). Thus we have the ASP.Net WebForm PostBack event model.

By now you should see that, as the page on the client is simply an HTML
form, pressing the ENTER key would indeed submit the page back to its own
URL. So, you're first assumption ("in ASP.NET web form, a form will only
be submitted (post back) when a special button is clicked") is wrong. In
fact, we get questions almost daily about how to PREVENT an ASP.Net page
from posting back when the ENTER key is pressed.

What you may be mixing up is in regards to the event model I described. In
order for the server to handle an event from a specific Control (form
element on the client HTML document), the server must know which Control
(form element on the client HTML document) was in fact clicked (or
changed). This brings us to the second element of the ASP.Net event model,
which is how to tell which Control caused the event.

Again, we're talking about a plain vanilla HTML document on the client
side. So, how does an HTML form tell the server anything? It does so via
the form fields whose values are posted back to the form handler. Now, how
would an HTML form send information about a client-side event to the
server in its form values collection? First, you would need a client-side
event handler. This is available through JavaScript (an "onclick" event
handler in JavaScript, for example, or an "onchange" event handler for
something like a drop-down list box). Second, you would need a hidden form
field that the JavaScript can put a value into. In fact, ASP.Net
automatically generates such JavaScript and the appropriate form fields
when you insert a Control into an ASP.Net page.

So, the user clicks a button. The "onclick" JavaScript event-handler for
that button is fired, which then puts the ID of the button into one hidden
form field, and the value of the button into another hidden form field.
The value isn't important with a button, but, for a textbox, for example,
the value is important. The form is posted back to the same Page class on
the server (via its URL being the same), which then reads the form field
values, and rebuilds the page according to your custom Event Handler
methods in that Page class. Then it returns a modified version of the same
HTML document to the client, which starts the whole process all over
again.

There is a lot more to it than that, but hopefully the appetizer will whet
your appetite.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Ambiguity has a certain quality to it.

"guoqi zheng" <no@sorry.com> wrote in message
news:72******************************@ureader.com. ..
In a regular html form, when user press "enter" key, the form will be
submitted.

However, in ASP.NET web form, a form will only be submitted (post back)
when
a special button is clicked. Many user get used to click "enter" key to
submit a form. How can I use "enter" key to submit/postback in ASP.NET.

Thank,

Guoqi Zheng
http://www.ureader.com


Nov 19 '05 #5
When I first see this long answer, I was thinking that another school pro. I
am not going to read it.

But after I read it... Thanks for a lot for the detail explaination.

I know what to do now.

Thanks.

regards,

Guoqi Zheng
http://www.ureader.com
Nov 19 '05 #6
You're very welcome, Guoqi, and thank YOU for taking the time to read it!

--

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

"guoqi zheng" <no@sorry.com> wrote in message
news:c0******************************@ureader.com. ..
When I first see this long answer, I was thinking that another school pro.
I
am not going to read it.

But after I read it... Thanks for a lot for the detail explaination.

I know what to do now.

Thanks.

regards,

Guoqi Zheng
http://www.ureader.com

Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: roger31 | last post by:
Hello - I created a simple website with one page. This simple page has only one text box (asp:Textbox) and no other controls. When i bring the siteup in VS2005 and press enter with the cursor...
2
by: promiscuoustx | last post by:
Hi again all!! I am trying to write my program below to validate user input. In other words, if the user inputs something like "1a2.34", I need to return a message that states invalid data and for...
8
by: sara | last post by:
I have a report that runs fine with data. If there is no data, I have its NO Data event sending a MsgBox and cancelling the report. Then it seems I still get the 2501 message on the Open Report...
22
by: fjm | last post by:
Well.. I'm back with another simple question but I'm not sure what the term is so I can't google it. I think it may have to do with $_SERVER What I am after is a form that will insert data into a...
9
by: learning | last post by:
Hi! Here's my situation: I have one textfield with one 'submit' button in PAGE1.PHP. When I click on the 'submit' button I am sent to PAGE2.PHP where I have a "switch" routine that checks...
1
by: RyanT | last post by:
Access 2000 Windows XP I have a small form with two text boxes: - User ID - Password The form also has two command buttons: - Login - Cancel
1
by: daonho | last post by:
I tried to use javascript to trigger up the button click function when user press enter key from the textbox. This function work fine with a single button click such has login page. However, if the...
6
by: Mark B | last post by:
I have a function that looks up a SQL table to see if a search term matches. It works fine but so far there are two things yet to work: 1) After entering a search term and pressing Enter, nothing...
3
by: =?Utf-8?B?V2ViQnVpbGRlcjQ1MQ==?= | last post by:
In the page_load event i need to see which event fired the post back. what here allows this. I specificly want to know if the enter key was pressed. but i need to check for others. -- (i''ll be...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...

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.