如何使 asp:button 成为向 asp:textbox 输入文本时的默认按钮
在文本框中输入文本后如何设置默认按钮。这是我到目前为止所拥有的。但它不起作用
<td>
<asp:Label ID="displayrowLabel" runat="server" Text="# of Rows Displayed:"></asp:Label>
<asp:TextBox ID="displayRowQuery" runat="server"></asp:TextBox>
<asp:Button ID="displayRowButton" runat="server" Text="Click" OnClick="ddlPageItems_SelectedIndexChanged" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="displayRowQuery" ValidationExpression="[1-9][0-9]*" ErrorMessage="Wrong Input" />
</td>
</tr>
</table>
</PagerTemplate>
我尝试添加一些 jquery 来处理这个问题:
<script type="text/javascript">
$("displayRowQuery").keyup(function (event) {
if (event.keyCode == 13) {
$("displayRowButton").click();
}
});
How can I set default button after text is entered into a text box. This is what I have so far. But it doesn't work
<td>
<asp:Label ID="displayrowLabel" runat="server" Text="# of Rows Displayed:"></asp:Label>
<asp:TextBox ID="displayRowQuery" runat="server"></asp:TextBox>
<asp:Button ID="displayRowButton" runat="server" Text="Click" OnClick="ddlPageItems_SelectedIndexChanged" />
<asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="displayRowQuery" ValidationExpression="[1-9][0-9]*" ErrorMessage="Wrong Input" />
</td>
</tr>
</table>
</PagerTemplate>
I tried adding some jquery to handle this:
<script type="text/javascript">
$("displayRowQuery").keyup(function (event) {
if (event.keyCode == 13) {
$("displayRowButton").click();
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您有一组需要默认按钮的控件,您还可以为 asp:panel 设置默认按钮。
基本上:
http://www.aspnettutorials.com/tutorials/controls/defaultbutton -面板-aspnet.aspx
You can also set a default button for an asp:panel if you have a group of controls you need a default button for.
Basically:
http://www.aspnettutorials.com/tutorials/controls/defaultbutton-panel-aspnet.aspx
您的 id 选择器中缺少“#”:
编辑: 正如 @Nicolás 所指出的,您可能必须用
ClientId
替换 id 选择器,如下所示:You're missing the "#" in your id selector:
Edit: As @Nicolás has pointed out, you may have to substitute the id selectors with
ClientId
like this: