By 06/02/2014 17 Comments

How To Prevent Cut, Copy and Paste Operations in an ASP.NET TextBox using jQuery

Bind() function

  • The jQuery bind() function binds one or more events to a handler. Observe how convenient it is to list multiple events (cut copy paste) together and bind it to a handler
  • It is useful when we want to perform more than one task by press single button

Following examples describes How bind() function works in asp.net using JQuery

Code snippet of JQuery.

    <script type="text/javascript" src="Scripts/jquery-1.8.2.js"></script>  <!-- call jquery file or library into asp.net page --->
    <script>
        $(document).ready(function() { // this is a function which is called by browser when it loads a webpage

            $('[id$="TT_TextBox1"]').bind('cut copy paste', function (e) { // trigger bind() functions, pass 2 parameters, first (three events to the handler), second an unknown function with e as a parameter

                e.preventDefault(); // prevent post back to the server 
                $("#TT-paragraph").text('You cannot ' + e.type + ' text!'); // text() function pass message as an argument which to be displayed on TT-paragraph, e.type display the type of an event to be triggered

            });

        });

    </script>

Code snippet of ASP.NET

<!--- Following code renders text field and label control on browser --->

<asp:Label runat="server" Text="Write your Email"></asp:Label>
        <asp:TextBox ID="TT_TextBox1" runat="server" style="width: 200px;" Text="Try copying and pasting text here" /><br />
        <br/>
        <p id="TT-paragraph"></p>






Posted in: ASP.NET, jQuery

Leave your valuable Comment

Have a natural attraction for women cosmetics and replica watches uk clothes, no
more than two for men the most attractive one, is to make their own driving experience, happy and can serve as the facade of the car, another is to highlight the taste edify sentiment rolex replica watch. The replica rolex is undoubtedly the most fashionable accessories, wear a suit to attend the activities, but also get a decent match on the replica watches .