TextBox on GridView causing a button click event t

2019-07-29 18:14发布

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.

3条回答
放我归山
2楼-- · 2019-07-29 18:43

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

查看更多
Anthone
3楼-- · 2019-07-29 18:53

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.

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-07-29 18:54

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;
查看更多
登录 后发表回答