473,385 Members | 1,766 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,385 software developers and data experts.

preventing carriage return from causing postback

I have a simple form with a textbox and a command button,
both web form controls (not raw HTML controls). I notice
that when the user enters text in the textbox and hits
carriage return, the form posts back. Is there a way to
prevent this?

I think it is undesirable for two reasons
1) Developer must support re-rendering the page even if
no events fire, which is another path through the code to
worry about (not always trivial if viewstate isn't being
used)
2) May be confusing to the user who will assume hitting
return is the equivalent of clicking some default button;
it isn't, because no events fire

Any suggestions would be welcome.
Nov 17 '05 #1
1 2199
You can intercept the client side enter keypress event of the text box and
then click do what you want using javascript code.
Here's a good example:
http://www.kamp-hansen.dk/pages/show...d=21&menuid=18

You could also try using this free control.
http://www.metabuilders.com/tools/DefaultButtons.aspx

And here's a good article on the subject:
http://www.allasp.net/enterkey.aspx

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://Steve.Orr.net
Hire top-notch developers at http://www.able-consulting.com

"Steve" <st***@mintonweb.com> wrote in message
news:0d****************************@phx.gbl...
I have a simple form with a textbox and a command button,
both web form controls (not raw HTML controls). I notice
that when the user enters text in the textbox and hits
carriage return, the form posts back. Is there a way to
prevent this?

I think it is undesirable for two reasons
1) Developer must support re-rendering the page even if
no events fire, which is another path through the code to
worry about (not always trivial if viewstate isn't being
used)
2) May be confusing to the user who will assume hitting
return is the equivalent of clicking some default button;
it isn't, because no events fire

Any suggestions would be welcome.

Nov 17 '05 #2

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

Similar topics

3
by: Canes_Rock | last post by:
The information posted at: ...
5
by: Ferdi | last post by:
I have a WebForm with one control: A HTML INPUT control with the property "runat=server" set. If this page is running and I set the cursor in this control and enter "Carriage return", the page...
1
by: Wolfgang Schmidt | last post by:
Hello, I have several datagrids in my application. At the moment, data rows which are in editmode can only be saved by clicking the corresponding save button. I would like to add the function...
1
by: John | last post by:
Hi all, I have a situation where I'm using a modal dialog to merely show the user some data. Once the user has finished, there is only one button to click to return to the previous (parent) page...
5
by: Jurgen Appelo | last post by:
I'm at a loss here... My FormView control automatically performs a databind at each postback on the server. But in some cases I don't want this to happen. Like when the business layer decides that...
12
by: Mark Rae | last post by:
Hi, See the previous thread Request.Form abuse in this newsgroup... I'm looking for a simple and efficient way to prevent people hijacking the <formtags on my websites and using them to send...
4
by: whitej77777 | last post by:
I am trying to write a user defined function that will allow me to strip off the last carriage return and line feed from a text field. We have address fields stored in a text field for our ERP...
2
by: chrisp | last post by:
I have an ASP.NET 2 page with a button that causes a credit card transaction to be authorised. The authorisation procedure may take a few seconds and so I want to prevent the user from clicking the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.