让ASP.NET响应键盘的方法

081217

还有一个方法就是把Button加个style="display:none;"

http://topic.csdn.net/u/20081217/15/064c4a7d-8189-4648-a7e1-0d99e60f4c36.html

又有人提问了,要隐藏Button.直接设置为Visible=False生成的代码是这样:

  1. <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAgKA94SLAgLs0bLrBspGCnzAQ9B96G6xK5QxbFOy1i+k" /> 

所以要用下面的方法。

  1. <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" Height="0px" Width="0px" />

今天论坛上有人问,我试了一下,成功了,那个朋友给我了满分,呵呵,记录下来,以备再问,呵呵。

http://topic.csdn.net/u/20081208/09/5f9c15d5-b605-47a3-86f6-aafd09242801.html

http://topic.csdn.net/u/20081217/13/5293b3a8-2e3b-4268-b433-d26705374270.html?seed=554615676

前台

  1. <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="test_Default" %>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" >
  4. <head runat="server">
  5.     <title>让ASP.NET响应键盘的方法</title>
  6.     <script type="text/javascript">
  7.      function EnterTextBox()
  8.     {
  9.          if(event.keyCode == 13 && document.all["TextBox1"].value != "")
  10.            {
  11.              event.keyCode = 9;
  12.              event.returnValue = false;
  13.               document.all["Button1"].click();
  14.           }
  15.      }
  16.    </script>
  17. </head>
  18. <body onkeypress="return EnterTextBox()">
  19.     <form id="form1" runat="server">
  20.     <div>
  21.         <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
  22.         <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
  23.         </div>
  24.     </form>
  25. </body>
  26. </html>

后台

  1. using System;
  2. using System.Data;
  3. using System.Configuration;
  4. using System.Collections;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. public partial class test_Default : System.Web.UI.Page
  12. {
  13.     protected void Page_Load(object sender, EventArgs e)
  14.     {
  15.     }
  16.     protected void Button1_Click(object sender, EventArgs e)
  17.     {
  18.         Response.Write("回车");
  19.     }
  20. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值