简体   繁体   English

在GridView中并非总是会触发Asp.net Keydown事件

[英]Asp.net Keydown Event not always fired within GridView

Within a griview (using IE), cells in one column are clickable (through gridview row command event) and once a cell is clicked it displays a hidden textbox (visible = false before the cell is clicked); 在griview中(使用IE),可单击一列单元格(通过gridview行命令事件),一旦单击单元格,它将显示一个隐藏的文本框(在单击该单元格之前,visible = false); users can enter text into the textbox and to allow saving changes made to the textbox users are told to press Tab key. 用户可以在文本框中输入文本,并允许保存对文本框所做的更改,并告知用户按Tab键。 The saving is done through using Javascript by checking keycode in keydown event, it simply checks when keycode = 9 (Tab key) __doPostback('OnClick','SaveButton'); 通过使用Javascript通过在keydown事件中检查键码来完成保存,它只检查何时keycode = 9 (Tab key) __doPostback('OnClick','SaveButton'); in codebehind SaveButton onclick event simply calls a store procedure to save the new text changes into database. SaveButton onclick事件SaveButton中,只需调用存储过程即可将新文本更改保存到数据库中。

The problem I have is keydown event is not ALWAYS fired though it works most of the time. 我遇到的问题是虽然大多数情况下都不会触发keydown事件。 There seems to be no difference to the situation when it works and when it doesn't, so to me it's a bit random and I have to emphaise that it works 90% of the time. 当它可以工作和什么时候不工作时,情况似乎没有什么区别,所以对我来说,这有点随机,我必须强调它在90%的时间内都可以工作。

Worth mentioning that when users click the cell to edit the textbox, gridview row updating event is fired first since I need to enable gridview row updating event not only for this column text changes but also for other columns data updating. 值得一提的是,当用户单击单元格以编辑文本框时,首先会引发gridview行更新事件,因为我不仅需要为此列文本更改而且还需要为其他列数据更新启用gridview行更新事件。

When everything 'works' after user pressing the Tab key, the event sequence is: 当用户按下Tab键后一切都正常运行时,事件序列为:

  1. Gridview row updating Gridview行更新
  2. Keydown/SaveButton click Keydown / SaveButton单击
  3. Gridview row updating Gridview行更新

I don't understand what triggers the event 3 ie the second gridview row updating event though it doesn't do any harm to anything as it's after the text being saved into database. 我不明白是什么触发了事件3,即第二个gridview行更新事件,尽管它对文本保存到数据库之后没有任何危害,但它不会对任何事件造成任何损害。 But when pressing Tab key doesn't work (text not saved) the second gridview row updating event is not fired; 但是,当按Tab键不起作用(未保存文本)时,不会触发第二个gridview行更新事件; only the 1st row updating event is fired and textbox changes are lost reverting back to the original text. 仅会触发第一行更新事件,并且丢失文本框的更改并恢复为原始文本。

I'm new to asp.net and hope someone can shred some light on this problem. 我是asp.net的新手,希望有人可以对这个问题有所了解。

I found out why GridView row updating event fired for the 2nd time, it's because AutoPost for the editable textbox being set to True. 我发现了为什么第二次触发GridView行更新事件,这是因为可编辑文本框的AutoPost设置为True。

silly me... 愚蠢的我...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM