You must Sign In to post a response.
  • Category: ASP.NET

    How to disable the cut copy select and right click from the asp.net webpage?


    Are you looking for information on online test application? Want to know how to disable the cut copy select and right click from the asp.net webpage? Read this thread to learn more about disabling certain options with examples.



    Hello,
    I want to make a simple demo application like online test. I Completed the full, but now my only need is that I want to disable the select ,cut ,copy and the right click option on my webpage with out using java script
  • #722004
    Hi,

    Try like this


    <asp:TextBox ID="YourTextboxId" runat="server" oncopy="return false" onpaste="return false" oncut="return false" ondelete="return false"></asp:TextBox>

    or

    <script language="javascript" type="text/javascript">
    function nocutcopypaste()
    {
    return false;
    }
    </script>


    <asp:TextBox ID="TextBox1" runat="server" oncopy="return nocutcopypaste()"> </asp:TextBox>



    Check the below link

    http://www.aspdotnet-suresh.com/2011/10/how-to-disable-copy-cut-and-paste-ctrl.html

    http://csharpdotnetfreak.blogspot.com/2009/01/disable-copy-paste-javascript-right.html

    Thanks,
    Mahesh

    Thanks & Regards,
    Mahesh Durgam

  • #722026

    Hi,

    Step1: If you want to prevent copy whole content of web page then use on dragstart as false and on select start as false inside of body tag like below.

    <body ondragstart="return false" onselectstart="return false">
    // Your content placed here
    </body>


    Step2: If you want prevent cut, copy, paste text in your text box then try like this way

    <asp:TextBox ID="TextBox1" runat="server" oncopy="return false" onpaste="return false"
    oncut="return false"></asp:TextBox>


    Regards
    N.Ravindran
    Your Hard work never fails

  • #722049
    Above answer looking good. You can also achieve this task in jquery.

    Jquery Example:-

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

    <!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>
    <title>How to Disable Copy, Cut and Paste Options in textbox using jQuery</title>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
    <script type="text/javascript">
    $(function() {
    $('#txtusername').bind("cut copy paste", function(e) {
    e.preventDefault();
    });
    });
    </script>
    </head>
    <body>
    <div>
    <form runat="server">
    <asp:TextBox ID="txtusername" runat="server"></asp:TextBox>
    </form>
    </div>
    </body>
    </html>



    Thanks & Regards
    G.Renganathan
    Nothing is mine ,Everything is yours!!!

  • #722056
    Thanks to all..
    Shalini Rathore

  • #722182
    Hi Shalini,

    Use the below body in your page to prevent copy , paste & cut.

    <body oncopy="return false;" onpaste="return false;" oncut="return false;">
    your content here...
    </body>

  • #728293
    Copy and paste the following javascript in your web page:

    <script language="javascript" type="text/javascript">
    function disableselect(e) {
    return false
    }
    function reEnable() {
    return true
    }

    document.onselectstart = new Function("return false")


    if (window.sidebar) {
    document.onmousedown = disableselect // for mozilla
    document.onclick = reEnable
    }

    function clickIE() {
    if (document.all) {
    (message);
    return false;
    }
    }


    document.oncontextmenu = new Function("return false")

    var element = document.getElementById('tbl');

    element.onmousedown = function () { return false; } // mozilla

    </script>

    Note: For mozilla add -moz-user-select:none in style of the body tag where you want to disable those options..


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.