In my webpage I want to disable copy and cut option in context menu on textbox.
Asked
Active
Viewed 1.5k times
5
-
Means you do not want to allow user right click or you want to handle Cntrl+C some what – Developer Mar 01 '11 at 05:34
-
2At the end of the day if someone wants to do it bad enough they will find a way. There is no way to ensure that data can not be copied from a webpage. – RDL Mar 01 '11 at 05:49
5 Answers
9
This is my first post and I hope it will help. Try this one:
<asp:TextBox ID="someId" runat="server" oncopy="return false" onpaste="return false" oncut="return false" ondelete="return false"></asp:TextBox>
It will work for copy, paste, cut, and delete on most of the input controls.

Chris Catignani
- 5,040
- 16
- 42
- 49

user2212025
- 91
- 1
- 3
9
<asp:TextBox ID="TextBox1" runat="server" oncopy="return false"> </asp:TextBox>

Student
- 3,469
- 7
- 35
- 42
1
Not sure if you're looking for a non asp way but I just found out about on cut method in JavaScript. Do the following for your input:
<input oncopy='prevent()>
<script>
function prevent()
{
event.preventDefault();
}
</script>
Works for me. Tested on chrome. Also disables copying from the context menu. Additionally this works for oncut and onpaste methods. Still trying to find a way for ondelete though.

Craig Wayne
- 4,499
- 4
- 35
- 50
1
You can also add a javascrip function to show a alert
<script language="javascript" type="text/javascript">
function nocopy()
{
alert("Copying is not allowed!");
return false;
}
</script>
<asp:TextBox ID="TextBox1" runat="server" oncopy="return nocopy()"> </asp:TextBox>

Student
- 3,469
- 7
- 35
- 42
0
Try this
<asp:TextBox ID="txtPrevent" runat="server" oncopy="return false"
oncut="return false">
</asp:TextBox>
for more see this link

Bhanu Prakash Pandey
- 3,805
- 1
- 24
- 16