BobC
BobC

Reputation: 412

TextBox on GridView causing a button click event to fire

I've been chasing this one around for a couple of days and it's starting to drive me a bit batty.

I have a text box on a Gridview which I'm allowing some data to be edited. When the enter key is hit, the TextChanged event happens, like I'd expect, but then it also fires the OnClick event of a button on the form.

I tried removing the button and it just moves to the next button on the form, so there's something about this that's making it think the enter key is pressing the button.

I've tried to Google it, but I'm not seeing much. I tried searching here, but it seems to be unusual enough that my search terms aren't catching it. Any help or suggestions would be most welcome.

Upvotes: 1

Views: 2387

Answers (3)

bytebender
bytebender

Reputation: 7491

Try setting the UseSubmitBehavior="False" on the buttons on your page.

Upvotes: 2

anna
anna

Reputation: 11

Change the AutoPostBack property of the textbox to true. By doing this you don't have to bother about any button's on submit behaviour also.

txtbox.AutoPostBack = true;

Upvotes: 1

sipsorcery
sipsorcery

Reputation: 30699

Your buttons have properties called IsCancel and IsDefault. If you disable them it will solve your issue.

Those properties allow a button to be treated as the default action for clicking the enter and escape keys.

Upvotes: 0

Related Questions