Click here to Skip to main content
15,867,330 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 64.9K   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

 
GeneralMy vote of 5 Pin
Member 431784027-Sep-18 19:48
Member 431784027-Sep-18 19:48 
GeneralMy vote of 5 Pin
zhangtai19-Sep-12 17:14
zhangtai19-Sep-12 17:14 
GeneralReason for my vote of 5 I learnt something new. Pin
kadu.sumit17-Jan-12 19:50
kadu.sumit17-Jan-12 19:50 
GeneralReason for my vote of 5 Good Tip Pin
mandar130512-Sep-11 3:02
mandar130512-Sep-11 3:02 
GeneralReason for my vote of 2 Does not work in all browsers Pin
Kikoz6830-Aug-11 14:49
Kikoz6830-Aug-11 14:49 
Generalnice Pin
the headless nick2-Aug-11 0:29
professionalthe headless nick2-Aug-11 0:29 
GeneralReason for my vote of 4 http://ribbs.usps.gov/onecodesolutio... Pin
the headless nick2-Aug-11 0:25
professionalthe headless nick2-Aug-11 0:25 
GeneralReason for my vote of 5 inspired! Thanks ;] Pin
Omar Gameel Salem28-Feb-11 9:12
professionalOmar Gameel Salem28-Feb-11 9:12 
GeneralReason for my vote of 5 excellent Pin
Sumit P27-Dec-10 6:56
Sumit P27-Dec-10 6:56 
GeneralReason for my vote of 5 good one Pin
Pranay Rana24-Dec-10 0:21
professionalPranay Rana24-Dec-10 0:21 
GeneralYes it works Pin
Sandesh M Patil23-Dec-10 4:03
Sandesh M Patil23-Dec-10 4:03 
GeneralReason for my vote of 5 OK, I get it but if the user used Ct... Pin
Layth Rafea23-Dec-10 4:01
Layth Rafea23-Dec-10 4:01 
GeneralOh its your sole opinion then, in large oranisation most of ... Pin
Sandesh M Patil21-Dec-10 6:23
Sandesh M Patil21-Dec-10 6:23 
GeneralYes, this works. But what difference does it make? I don't... Pin
wallkao3bei421-Dec-10 5:44
professionalwallkao3bei421-Dec-10 5:44 
GeneralThanks a lot, very nice Tip Pin
Mohamed M. El Sheikh20-Dec-10 23:13
Mohamed M. El Sheikh20-Dec-10 23:13 
GeneralReason for my vote of 5 Thanks a lot, very nice Tip Pin
Mohamed M. El Sheikh20-Dec-10 23:13
Mohamed M. El Sheikh20-Dec-10 23:13 
GeneralThanks. Nice to know! Pin
Dr.Walt Fair, PE19-Dec-10 4:27
professionalDr.Walt Fair, PE19-Dec-10 4:27 
GeneralThanks kunal Pin
Sandesh M Patil26-Nov-10 4:27
Sandesh M Patil26-Nov-10 4:27 
GeneralReason for my vote of 5 Small but Good Tip. Keep posting reg... Pin
Kunal Chowdhury «IN»26-Nov-10 4:19
professionalKunal Chowdhury «IN»26-Nov-10 4:19 
GeneralAn another knowledge i got from here...Thank you Smile Pin
kpl723-Nov-10 1:06
kpl723-Nov-10 1:06 
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.