textbox control question

D

djc

I noticed that after entering text into a textbox on an asp.net webform and
then hitting the enter key that a postback appears to be performed.

1) what event can I write to in order to perform an action at that time?
2) How can I prevent any postback from happening on textboxes that I do not
want to handle this event on?

any info is appreciated. Thanks.
 
S

Scott M.

The postback occurs because you hit ENTER, it is not caused by the textbox.

If you had written code in the textbox's server event: TextChanged, then
that event would fire but the fact that you changed the text isn't what
caused the postback.

If you don't want to handle an event, simply don't write an event handler
for that event.
 
R

Rajesh Patel

1. textchanged event

2. make autopostback property false.

Regards,

Rajesh Patel
 
D

djc

Hi Scott, thanks for the reply.

I'm still a little confused on the behavior of hitting ENTER. 1) What event
fires when hitting ENTER when the focus is in a text box? 2) I have
autopostback set to false but a post back still occurs. Can I prevent this
postback from happening? Since nothing actually happens in my app the
postback may confuse the user.

thanks again.
 
J

John M Deal

This is just the behavior of the browser. When a single line text box
(as opposed to a multiline text area) has focus and the user presses the
enter key the browser triggers the first submit button on the page. You
may be able to intercept the keystrokes for the page and "eat" the
keypress, or perhaps you could put an inocuous "bogus" button on the
page as the first button and disable it's ability to submit. Both of
these solutions would require javascript. I've never done this myself,
but I remember a team member creating an IE behavior to do the "eat",
but that only worked in IE (the company requirements allowed this).
Sorry I can't be more help.

Have A Better One!

John M Deal, MCP
Necessity Software
 
S

Scott M.

Hitting the ENTER key is the same thing as pressing a submit button. This
is the default action of the browser, not any code you've written.
AutoPostBack has nothing to do with this since this action is happening in
the client.

If nothing happens in your app upon submitting, then what is the textbox
used for?
 
D

djc

got it. Thanks.

John M Deal said:
This is just the behavior of the browser. When a single line text box
(as opposed to a multiline text area) has focus and the user presses the
enter key the browser triggers the first submit button on the page. You
may be able to intercept the keystrokes for the page and "eat" the
keypress, or perhaps you could put an inocuous "bogus" button on the
page as the first button and disable it's ability to submit. Both of
these solutions would require javascript. I've never done this myself,
but I remember a team member creating an IE behavior to do the "eat",
but that only worked in IE (the company requirements allowed this).
Sorry I can't be more help.

Have A Better One!

John M Deal, MCP
Necessity Software
 
D

djc

I didn't realize it was actually the submit button that the browser fired
when hitting ENTER. This will work fine as it saves the user a click if they
hit enter. I did not have any code tied to the submit button yet and thought
the ENTER key hit was seperate. If that were true then I didn't want a user
to mistakenly think there info was submitted when they hit ENTER if it
wasn't.

thanks again.
 

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

Top