Description:

In this article, I will explain how to prevent cut, copy and paste operation using Jquery.

In some scenario, we may require the functionality which means user should not be allowed to cut, copy text from the textbox and paste text within textbox.

We can easily disable cut, copy, and paste operation on textbox using JQuery.

To restrict users to copy, paste and cut contents from textbox, use preventDefault() method.

preventDefault() method used to prevent the actual occurring of events. It is similar to ‘return false’ when events fire.

Example program:

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
    </script>
    <script type="text/javascript">
        $(function () {
            $('#txtpwd').bind("cut copy paste", function (e) {
                e.preventDefault();
                alert('Alert: Disabled ' + e.type + " Operation");
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="lblpwd" runat="server" Text="Enter Password:"></asp:Label>
        <asp:TextBox ID="txtpwd" runat="server" ></asp:TextBox>
    </div>
    </form>
</body>
</html>


Disable Cut,Copy,Paste operation on a textbox with jquery, Disable Cut,Copy,Paste operation on an asp.net textbox , Disable Cut,Copy,Paste operation on an page using jquery, Prevent Cut,Copy,Paste operation on a page.

0 comments:

Post a Comment

 
Top