Sunday 8 December 2013

How to Disable Cut, Copy, Paste Options On a Textbox in C#.Net


                       
Today am going to explain how to disable cut, copy, paste options on a text box using ASP.NET.

In our applications sometimes we need to disable cut, copy, paste options. It is mainly helpful when someone tries to paste the email/username and password fields. At that time for security reasons we have to disable these options. Now let’s see how can we do this in ASP.NET?

First take a text box.

<asp:TextBox ID="txtRead" runat="server"></asp:TextBox>

We have taken a new textbox and declared its name as txtRead.
Now declare three public property names as

oncopy
oncut
onpaste


Now return their values false as shown below.

oncopy=”return false”
oncut=”return false”
onpaste=”return false”
Now the entire line together is

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

This way we can restrict the cut or copy of the content present in the textbox. And also we can disable the pasting option in the textbox.


No comments:

Post a Comment