Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

How to Prevent a Drag and Drop Text and Copy Paste Text in your textbox Control

4.95/5 (29 votes)
22 Dec 2010CPOL 71.3K  
How to prevent a drag and drop text and copy paste text in your textbox control

Introduction

You can prevent a drag and drop value from your page and a copy paste text in your textbox.

For example: I have a textbox:

ASP.NET
<asp:TextBox ID="txtSeqNumber" runat="server"  Width="150">

How can I prevent this? Most of the time, this error is reported by testers. The simplest solution is as follows.

Just add the following JavaScript in the code:

ASP.NET
<asp:TextBox ID="txtSeqNumber" runat="server" onDrop="blur();return false;" 
	onpaste="return false"  Width="150">

Because of blur() function, the txtSeqNumber lost its focus and we are not able to drag and drop the text.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)