Click here to Skip to main content
Click here to Skip to main content

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

, 22 Dec 2010
Rate this:
Please Sign up or sign in to vote.
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: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: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)

About the Author

$andesh M Patil
Software Developer (Senior)
India India
Sandesh has a 6 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 Pinmemberzhangtai19-Sep-12 17:14 
GeneralReason for my vote of 5 I learnt something new. Pinmemberkadu.sumit17-Jan-12 19:50 
GeneralReason for my vote of 5 Good Tip Pinmembermandar130512-Sep-11 3:02 
GeneralReason for my vote of 2 Does not work in all browsers PingroupKikoz6830-Aug-11 14:49 
Generalnice Pinmemberncik92-Aug-11 0:29 
GeneralReason for my vote of 4 http://ribbs.usps.gov/onecodesolutio... Pinmemberncik92-Aug-11 0:25 
GeneralReason for my vote of 5 inspired! Thanks ;] PinmemberOmar Gamil28-Feb-11 9:12 
GeneralReason for my vote of 5 excellent PinmemberSumit Kumar Pranav27-Dec-10 6:56 
Reason for my vote of 5
excellent
GeneralReason for my vote of 5 good one PinmemberPranay Rana24-Dec-10 0:21 
GeneralYes it works PinmemberSChristmas23-Dec-10 4:03 
GeneralReason for my vote of 5 OK, I get it but if the user used Ct... PinmemberScofield Puzzle23-Dec-10 4:01 
GeneralOh its your sole opinion then, in large oranisation most of ... PinmemberSChristmas21-Dec-10 6:23 
GeneralYes, this works. But what difference does it make? I don't... Pinmemberwallkao3bei421-Dec-10 5:44 
GeneralThanks a lot, very nice Tip Pinmembermelsheikh20-Dec-10 23:13 
GeneralReason for my vote of 5 Thanks a lot, very nice Tip Pinmembermelsheikh20-Dec-10 23:13 
GeneralThanks. Nice to know! PinsubeditorWalt Fair, Jr.19-Dec-10 4:27 
GeneralThanks kunal PinmemberSChristmas26-Nov-10 4:27 
GeneralReason for my vote of 5 Small but Good Tip. Keep posting reg... PinmvpKunalChowdhury26-Nov-10 4:19 
GeneralAn another knowledge i got from here...Thank you Smile Pinmemberkpl723-Nov-10 1:06 
GeneralReason for my vote of 5 I learned new thing for sure and Tha... PinmemberSri Oleti19-Nov-10 9:44 
GeneralReason for my vote of 5 good tip. keep up the good work. PinmemberRakesh Agarwal ji19-Nov-10 2:29 

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140718.1 | Last Updated 22 Dec 2010
Article Copyright 2010 by $andesh M Patil
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid