How to validate or protect to perform right click via mouse as well as keyboard on the textbox using Java Script in asp.net c#

In this article, we can validate the textbox to perform the right key of as well as keyboard using java script , through java script we can set the alert message for this .


Java script code:-


<script language="javascript" type="text/javascript">
 
 function disableContextMenu() {
            alert("You cannot perform right click via mouse as well as keyboard");
            return false;
        } 
    </script> 

Source code:-
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="textboxvalidartion.aspx.cs" Inherits="textboxvalidartion" %>

<!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">
<head runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">



        function disableContextMenu() {
            alert("You cannot perform right click via mouse as well as keyboard");
            return false;
        } 
    </script> 

</head>
<body>
    <form id="form1" runat="server">
    <div>

        <asp:TextBox ID="txtmsg" runat="server" oncontextmenu="disableContextMenu();" ></asp:TextBox>

    </div>
    </form>
</body>
</html>

Out-Put:-



How to validate or protect to perform right click via mouse as well as keyboard on the textbox using Java Script in asp.net c# How to validate or protect to perform right click via mouse as well as keyboard on the textbox using Java Script in asp.net c# Reviewed by NEERAJ SRIVASTAVA on 12:57:00 PM Rating: 5

No comments:

Powered by Blogger.