Why is a button Click event also called when a textbox TextChanged event is called???

S

S_K

This is a weird problem..

I have a page with a textbox and a button (along with a bunch of other
stuff). Both the textbox and the button have their SEPERATE events
defined for the textchanged and click events. When I change the text
in the textbox the textchanged event is called as expected. But the
button click event is also called!?

Whats with that?!

Can anybody help? This is driving me crazy!

Thanks

Steve
 
B

bruce barker

possible reasons

1) you hit enter/return after changing the text. this will cause the
button to postback

2) you don't have autopostback set on the textbox, so the postback only
occurs when you hit the button.

-- bruce (sqlwork.com)
 
S

S_K

possible reasons

1) you hit enter/return after changing the text. this will cause the
button to postback

2) you don't have autopostback set on the textbox, so the postback only
occurs when you hit the button.

-- bruce (sqlwork.com)








- Show quoted text -

First, Thanks for responding.

Second, The first possiblility makes sense. However, why would hitting
the <ENT> or return key cause a button event to fire? Is there any way
I can undo that?

Thanks again.
Steve
 
L

LVP

<script language=javascript type=text/javascript>
<!-- Script courtesy of http://www.web-source.net - Your Guide to
Professional Web Site Design and Development
function stopRKey(evt) {
var evt = (evt) ? evt : ((event) ? event : null);
var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement
: null);
if ((evt.keyCode == 13) && (node.type=="text")) {return false;}
}

document.onkeypress = stopRKey;
-->
</script>

From http://www.web-source.net/javascript_disable_enter_key.htm by John
Nitkowski
 
R

Robert Dunlop

Second, The first possiblility makes sense. However, why would hitting
the <ENT> or return key cause a button event to fire? Is there any way
I can undo that?

If you are using .NET 2.0, you can set the Button's UseSubmmitBehavior
property to false.
 

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

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top