ASP.NET中怎么把Button的Accesskey设成回车键 用户输完密码后,按回车也能进入,

有个登录页面.点击<登录按钮>可以进入

.我想让用户输完密码后,按回车也能进入,

相当于点击<登录按钮>


设置按钮的UseSubmitBehavior属性为True

服务器解析后的html就为submit按钮

 如果是ImageButton的话就用javascript控制了

//定义设置默认按钮函数
public static void SetDefEnterControl(System.Web.UI.Control Ctrl)
    {
        Page mPage = Ctrl.Page;
        string mScript;
        mScript = @"<script language=""javascript""> ";
        mScript += "function document.onkeydown() {";
        mScript += "var e = event.srcElement; ";
        mScript += "var k = event.keyCode; ";
        mScript += @"if (k == 13 && e.type != ""textarea"") { ";
        mScript += "document.all." + Ctrl.ClientID + ".click(); ";
        mScript += "event.cancelBubble = true; ";
        mScript += "event.returnValue = false; ";
        mScript += "} }</script>";

        if (mPage.IsClientScriptBlockRegistered("SetEnterControl") == false)
            mPage.RegisterClientScriptBlock("SetEnterControl", mScript);

        
    }


//在pageload()事件中在设置

SetDefEnterControl(ImageButton1);


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
含全套代码+数据库文件 mdb private sub txtoldpassword lostfocus if oldpassword <> txtoldpassword text then msgbox "密码不正确 " "密码错误" txtoldpassword setfocus end if end sub private sub form unload cancel as integer set mclsmidtier nothing lusersrs close userrs close set lusersrs nothing set userrs nothing end sub private sub startpos cmdadduser enabled true cmddeleteuser enabled true lstusers tabindex 0 txtusername tabindex 1 txtpassword tabindex 2 txtreenter tabindex 3 txtoldpassword tabindex 4 cmdadduser tabindex 6 cmddeleteuser tabindex 7 cmdchangepassword tabindex 8 lblpassword top 600 txtpassword top 600 lblreenter top 960 txtreenter top 960 lbloldpassword top 1320 txtoldpassword 1320 lblnewpassword top 1680 lstusers enabled true txtusername enabled true lblpassword visible true txtpassword visible true lblnewpassword visible false lblreenter visible false txtreenter visible false lbloldpassword visible false txtoldpassword visible false end sub private sub changepos cmdadduser enabled false cmddeleteuser enabled false lblpassword visible false txtpassword visible true txtpassword top 960 lblnewpassword top 960 lblreenter top 1320 txtreenter top 1320 lbloldpassword top 600 txtoldpassword top 600 txtoldpassword tabindex 1 txtpassword tabindex 2 txtreenter tabindex 3 lstusers enabled false txtusername enabled false lblnewpassword visible true lblreenter visible true txtreenter visible true lbloldpassword visible true txtoldpassword visible true end sub private const margin size 60 " in twips " variables for data binding private datprimaryrs as adodb recordset " variables for enabling column sort private m isortcol as integ
using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Data.OleDb; public partial class userShow : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { this.Label1.Text = System.DateTime.Now.ToString(); loadData(); } protected void Button2_Click(object sender, EventArgs e) { OleDbConnection conn; OleDbCommand cmd; string olecmd, oleString,value; value = this.TextBox1.Text; Session.Add("key", value); oleString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("news.mdb"); olecmd = "select * from userLoad where userName='"; olecmd += TextBox1 .Text.Trim(); olecmd += "'and userPassword='"; olecmd += TextBox2 .Text.Trim() + "'"; conn = new OleDbConnection();//实例化对象 conn.ConnectionString = oleString; cmd = new OleDbCommand(); cmd.Connection = conn; cmd.CommandText = olecmd; conn.Open(); OleDbDataReader dr = cmd.ExecuteReader(); if (this.TextBox1.Text.Trim() == "" || this.TextBox2.Text.Trim() == "") { Response.Redirect("usersub.aspx"); } if (dr.Read()) { Session["username"] = this.TextBox1.Text; Response.Redirect("todayNews.aspx"); } else { this.TextBox1 .Focus(); this.TextBox1 .Text = ""; this.TextBox2 .Text = ""; } conn.Close(); dr.Close(); } protected void Button3_Click(object sender, EventArgs e) { this.TextBox1.Focus(); this.TextBox1.Text = ""; this.TextBox2.Text = ""; } DataSet GetDataSet() { OleDbConnection conn; OleDbCommand cmd; conn = new OleDbConnection(); conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("news.mdb"); conn.Open(); cmd = new OleDbCommand(); cmd.CommandText = "select * from newsData where newsclassid=0"; cmd.Connection = conn; OleDbDataAdapter oleDA = new OleDbDataAdapter(); oleDA.SelectCommand = cmd; DataSet ds = new DataSet(); oleDA.Fill(ds, "newsData"); conn.Close(); return ds; } void loadData() { DataSet ds = GetDataSet(); GridView1.DataSource = ds; GridView1.DataBind(); } protected void GridView1_SelectedIndexChanged(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("userLogin.aspx"); } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; loadData(); } }

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值