我们可以在每个页面写上
< INPUT id = " PassWord " runat = " server " type = " password " onkeydown = " javascript:fnTrapKD('Login') " >
类似的代码 ,然后嵌入或链接一段 fnTrapKD函数的js代码完成这种效果 ,但这样应用的页面多了就会造成代码的混乱 , 因此有必要把他们封装起来. 在后台调用一个静态函数就可以达到效果,更加灵活.
步骤如下:
1.编写注册TextBox和Button的静态方法
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Cuyahoga.Web.UI
{
/// <summary>
/// Utility class that handles the ASP.NET default button issue.
/// Originally created by Janus Kamp Hansen - http://www.kamp-hansen.dk
/// Extended by Darrell Norton - http://dotnetjunkies.com/weblog/darrell.norton/
/// Tidied by Martijn Boland - http://www.cuyahoga-project.org
/
using System.Web.UI;
using System.Web.UI.WebControls;
namespace Cuyahoga.Web.UI
{
/// <summary>
/// Utility class that handles the ASP.NET default button issue.
/// Originally created by Janus Kamp Hansen - http://www.kamp-hansen.dk
/// Extended by Darrell Norton - http://dotnetjunkies.com/weblog/darrell.norton/
/// Tidied by Martijn Boland - http://www.cuyahoga-project.org
/