I am working on an mvc application. Two tables each have their individual submit button. Table1 has default submit on enter key. How do I change the submit button based on textbox focus?
我正在开发一个mvc应用程序。两个表都有各自的提交按钮。表1默认提交了enter键。如何更改基于textbox焦点的submit按钮?
<table>
...<td align="left"><%= Html.TextBox("name")%></td>
...<input id="nameSubmit" name="NameSubmit" type="submit" value="Search"/>
</table>
<table>
...<td align="left"><%= Html.TextBox("idNum")%></td>
...<input id="idSubmit" name="IdSubmit" type="submit" value="Search"/>
</table>
I tried using the panel, but "the DefaultButton of 'Panel1' must be the ID of a control of type IButtonControl".
我尝试使用面板,但是“‘Panel1’的DefaultButton必须是IButtonControl类型的控件的ID”。
Any ideas?
什么好主意吗?
1 个解决方案
#1
6
If you wrap each of the submits in <form>
tags that should help determine which submit was clicked as such:
如果您将每个提交都封装在
<table>
<form id="form1">
<td align="left"><input id="name" /></td>
<input id="nameSubmit" name="NameSubmit" type="submit" value="Search"/>
</form>
</table>
<table>
<form id="form2">
<td align="left"><input id="number" /></td>
<input id="idSubmit" name="IdSubmit" type="submit" value="Search"/>
</form>
</table>
This would make any Enter presses while the textbox was focused submit to the corresponding form.
这将使任何输入按下,而文本框被集中提交到相应的表单。
Here is a demo of this working, I hope that it helps you out.
这是这个工作的一个演示,我希望它能帮助你。
#1
6
If you wrap each of the submits in <form>
tags that should help determine which submit was clicked as such:
如果您将每个提交都封装在
<table>
<form id="form1">
<td align="left"><input id="name" /></td>
<input id="nameSubmit" name="NameSubmit" type="submit" value="Search"/>
</form>
</table>
<table>
<form id="form2">
<td align="left"><input id="number" /></td>
<input id="idSubmit" name="IdSubmit" type="submit" value="Search"/>
</form>
</table>
This would make any Enter presses while the textbox was focused submit to the corresponding form.
这将使任何输入按下,而文本框被集中提交到相应的表单。
Here is a demo of this working, I hope that it helps you out.
这是这个工作的一个演示,我希望它能帮助你。