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

  • Thread starter Thread starter S_K
  • Start date Start date
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
 
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)
 
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
 
<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
 
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.
 
Back
Top