ASP.NET2.0使用Enter Key作为默认提交问题分析(附源码)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了ASP.NET2.0使用Enter Key作为默认提交问题分析(附源码),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2692字,纯文字阅读大概需要4分钟。
内容图文
![ASP.NET2.0使用Enter Key作为默认提交问题分析(附源码)](/upload/InfoBanner/zyjiaocheng/379/5d33d494e33f48e5a9d72b5a9c6d5747.jpg)
本文实例分析了ASP.NET2.0使用Enter Key作为默认提交的方法。分享给大家供大家参考,具体如下:
网页开发中最烦人的事情之一就是为表单处理"Enter key" ,"Enter key"已经成为用户提交表单的偏好。虽然我们为用户提供了提交按钮,但是最简单也是最直接的方式仍然是:输入文字,然后回车完成提交
ASP.NET 2.0中为此提供了很好的解决方法。只需要将"defaultbutton"属性指定到想要引发事件的按钮控件的ID上就可以了。
在表单级别和面板级别(<asp:panel> 标记)均可以指定"defaultbutton"。当表单和面板中同时指定了defaultbutton,则如果在面板中触发了"Enter key",则执行面板中的
下面的实例代码中有一个表单和4个面板,报单和面板中都有按钮。情各位注意:在文本框中回车后会触发哪些按钮的事件
<form id="form1" runat="server" defaultbutton="btn1"> <div> <asp:TextBox ID="txt" runat="server"></asp:TextBox> <asp:Button ID="Button5" runat="server" Text="Cancel" OnClick="Button5_Click" /> <asp:Button ID="btn1" runat="server" Text="Submit" OnClick="btn1_Click" /> <asp:Panel ID="pnl1" runat="server" defaultbutton="Button1"> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" Text="Button1" OnClick="Button1_Click" /> </asp:Panel> <asp:Panel ID="Panel1" runat="server" defaultbutton="Button2"> <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox4" runat="server"></asp:TextBox> <asp:Button ID="Button2" runat="server" Text="Button2" OnClick="Button2_Click" /> </asp:Panel> <asp:Panel ID="Panel2" runat="server" defaultbutton="Button3"> <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox6" runat="server"></asp:TextBox> <asp:Button ID="Button3" runat="server" Text="Button3" OnClick="Button3_Click" /> </asp:Panel> <asp:Panel ID="Panel3" runat="server" defaultbutton="Button4"> <asp:TextBox ID="TextBox7" runat="server"></asp:TextBox> <asp:TextBox ID="TextBox8" runat="server"></asp:TextBox> <asp:Button ID="Button4" runat="server" Text="Button4" OnClick="Button4_Click" /> </asp:Panel> </div> </form> //The corresponding, sample events for the button clicks are protected void Button1_Click(object sender, EventArgs e) { Response.Write(Button1.Text); } protected void Button2_Click(object sender, EventArgs e) { Response.Write(Button2.Text); } protected void Button3_Click(object sender, EventArgs e) { Response.Write(Button3.Text); } protected void Button4_Click(object sender, EventArgs e) { Response.Write(Button4.Text); } protected void btn1_Click(object sender, EventArgs e) { Response.Write(btn1.Text); } protected void Button5_Click(object sender, EventArgs e) { Response.Write(Button5.Text); }
完整实例代码代码点击此处本站下载。
希望本文所述对大家asp.net程序设计有所帮助。
内容总结
以上是互联网集市为您收集整理的ASP.NET2.0使用Enter Key作为默认提交问题分析(附源码)全部内容,希望文章能够帮你解决ASP.NET2.0使用Enter Key作为默认提交问题分析(附源码)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。