Click here to Skip to main content
15,891,253 members
Articles / Web Development / ASP.NET
Tip/Trick

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

Rate me:
Please Sign up or sign in to vote.
4.95/5 (29 votes)
22 Dec 2010CPOL 67.5K   12   22
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)


Written By
Team Leader
India India
Sandesh has a 11 years of total professional experience in a software development. He first handled the computer in his school days when he was in 7th std working on Lotus. In summer vacation, the school authorities allowed him and other students to use the computers for practicing Lotus and playing different games Smile | :) .

He has done computer engineering. Currently he is working in Net 4.0 framework. Even though he is using .Net 4.0 framework for development but still he has not got a chance to work with newer technologies like MVC, WCF etc. However he always try to learn these technologies from his end and eagerly waiting for a chance to work with the newer technologies like MVC, WCF and Silverlight etc.

Comments and Discussions

 
GeneralReason for my vote of 5 I learned new thing for sure and Tha... Pin
Sri Oleti19-Nov-10 9:44
Sri Oleti19-Nov-10 9:44 
GeneralReason for my vote of 5 good tip. keep up the good work. Pin
Rakesh Agarwal198419-Nov-10 2:29
Rakesh Agarwal198419-Nov-10 2:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.