Virtual Keyboard implementation in asp.net c# and JavaScript
As we have seen many govt or bank website there almost on every website use the virtual keyword on login time. Many times we have used and many times we will not use. Basically, Virtual keyboard to prevent from malicious “Spyware” and “Trojan Programs”.
So In this article, we will learn how to implement virtual keyboard on login page using asp.net c#. As previously we have learned about how to create a login page in asp.net c#.
Source Code:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="virtual-keyboard.aspx.cs" Inherits="virtual_keyboard" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Virtual Keyboard implementation in asp.net c#</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<link type="text/css" href="css/jquery.keypad.css" rel="stylesheet" />
<script type="text/javascript" src="javascript/jquery.plugin.min.js"></script>
<script type="text/javascript" src="javascript/jquery.keypad.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("input[id$='Virtual_Keyboard']").click(function () {
if (!$(this).is(':checked')) {
$('#Username').keypad('destroy');
$('#Password').keypad('destroy');
} else {
$('#Username').keypad({ keypadOnly: true, layout: $.keypad.qwertyLayout, });
$('#Password').keypad({ keypadOnly: true, layout: $.keypad.qwertyLayout, });
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<fieldset style="width: 450px;">
<legend>Virtual Keyboard implementation in asp.net c#</legend>
<asp:TextBox runat="server" ID="Username" Placeholder="Username"></asp:TextBox>
<br />
<br />
<asp:TextBox runat="server" ID="Password" TextMode="Password" Placeholder="Password"></asp:TextBox>
<br />
<input type="checkbox" id="Virtual_Keyboard" />Use Virtual Keyboard<br />
<asp:Button runat="server" Text="Submit" ID="btnsubmit" OnClick="btnsubmit_Click" />
</fieldset>
</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 virtual_keyboard : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnsubmit_Click(object sender, EventArgs e)
{
if(Username.Text=="srinickraj" && Password.Text=="123456")
{
Response.Redirect("http://www.neerajcodesolutions.com");
}
else
{
Response.Write("<script>alert('Please enter valid Username and Password')</script>");
}
}
}
Important point
You can alter the layout of the keypad by specifying the keys per row as a string array. Use special characters for controls:
$.keypad.CLOSE - close the keypad
$.keypad.CLEAR - erase the entire field
$.keypad.BACK - erase the previous character
$.keypad.SHIFT - toggle between upper and lower case
$.keypad.SPACE_BAR - an extended space key
$.keypad.ENTER - the Enter key
$.keypad.TAB - the Tab key
$.keypad.SPACE - an empty space
$.keypad.HALF_SPACE - half an empty space
Note :You have need to download this code for css and javasrcipt package
Virtual Keyboard implementation in asp.net c# and JavaScript
Reviewed by NEERAJ SRIVASTAVA
on
8:55:00 PM
Rating:
nice post ....
ReplyDelete