Monday, October 21, 2013

Jquery to Prevent Cut, Copy and Paste for Textbox in Asp.net

1 comment
Jquery code to prevent cut , copy or paste for text box control in asp.net can be used in situation where you don't want user to paste the text directly into input control. Suppose you have applied validation on text box to accept only numerics or alphabets as input but user can manually paste in that particular control and there would  be no use of validation. In such case use the jquery to prevent user manually copy and paste data inside an input control.

Jquery to stop Cut, Copy and Paste in ASP.Net:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {


            $('#txtname').bind("cut copy paste", function (e)
            {
                e.preventDefault();
                alert("Cut, Copy not allowed");
            });

        });


    </script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:TextBox runat="server" ID="txtname"></asp:TextBox>
         
          
        </div>
    </form>
</body>

</html>

1 comment: