Tuesday, September 9, 2014

Disable copy, cut, paste and drop options in asp.net textbox using Jquery

Introduction: In this article today I am going to explain how we can disable copy, cut, paste and drop options in asp.net text box using Jquery

Description:

Add a webform to project. Add the below given script code between head tag of page:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
   <script type="text/javascript">
       $(function () {
           $('.disable').bind('cut copy paste drop', function (e) {
               e.preventDefault();
               alert('Cut,Copy,Drop and Paste options are disabled');
           });
       });
</script>

After that drag and drop the text box from Toolbox to webform and design the page as given below:

<fieldset style="width:400px;height:auto;align:center;">
    <legend>Disable Copy,Paste,Cut and Drop</legend>
    <table>
    <tr><td>Address</td><td><asp:TextBox ID="txtaddress" CssClass="disable" TextMode="MultiLine" runat="server"></asp:TextBox></td></tr>
    <tr><td></td><td>Dummy Text</td></tr>
    </table>
    </fieldset>

I add the class CssClass="disable" to text box.

Now build and run the project. 

Demo:
Disable copy, cut, paste and drop options in asp.net textbox using Jquery
Is this article helpful for you?
If yes post your comment to appreciate my work and fell free to contact me. You can like me on Facebook, Google+, Linkedin and Twitter via hit on Follow us Button and also can get update follow by Email.

No comments:

Post a Comment