enable enter key in textbox using java script in asp.net c#
Source Code:-
<%@
Page Language="C#" AutoEventWireup="true" CodeFile="enterbutton.aspx.cs" Inherits="enterbutton"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<title></title>
<script type="text/javascript">
function
EnterEvent(e) {
if
(e.keyCode == 13) {
__doPostBack('<%=Btnenterkey.UniqueID%>', "");
}
}
</script>
<style type="text/css">
.style1
{
width:
100%;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<table class="style1">
<tr>
<td align="right">
User Name
</td>
<td>
<asp:TextBox ID="txtusername" runat="server" Width="180px"></asp:TextBox>
</td>
</tr>
<tr>
<td align="right">
Password
</td>
<td>
<asp:TextBox ID="txtpwd" runat="server" onkeypress="return EnterEvent(event)"
Width="180px" TextMode="Password"
ClientIDMode="Static"></asp:TextBox>
<asp:Button ID="Btnenterkey" runat="server" Visible="false"
OnClick="Btnenterkey_Click"
/>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnsubmit" runat="server" OnClick="btnsubmit_Click" Text="submit" />
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
Code behind(c#):-
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using
System.Web.UI.WebControls;
public partial class enterbutton : System.Web.UI.Page
{
protected void Page_Load(object
sender, EventArgs e)
{
}
protected void btnsubmit_Click(object
sender, EventArgs e)
{
login();
}
protected void Btnenterkey_Click(object
sender, EventArgs e)
{
login();
}
protected void login()
{
if
(txtusername.Text == "Code Solution"
&& txtpwd.Text == "neeraj@123")
{
Response.Redirect("validator.aspx");
}
else
{
Response.Write("username/password is wrong");
}
}
}
Out-put:-
enable enter key in textbox using java script in asp.net c#
Reviewed by NEERAJ SRIVASTAVA
on
9:36:00 PM
Rating:
No comments: