Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Disable Drag and Drop Option in Textbox or Textarea Controls

Feb 28, 2013
Introduction

Here I will explain how to disable drag and drop option in textbox or textarea using JavaScript properties. 

Description:
  
In previous articles I explained JavaScript show number of characters left, JavaScript restrict user to enter only numbers, JavaScript allow limited characters in textarea, JavaScript remove special characters from textbox and many articles relating to
JavaScript, jQuery, asp.net. Now I will explain how to disable drag and drop option in textbox or textarea.

Previously I written one post JavaScript remove special characters from textbox to remove special characters from textbox at that time one reader has asked me the question like 

“Textbox removing special characters whenever I enter but if I select some special characters text and hold the text by mouse click and drop it in textbox it’s allowing how to restrict that drag and drop option?”

To stop drag and drop option in textbox or textarea we need to set some of properties in body tag for that check below 


<html>
<head>
</head>
<body ondragstart="return false" draggable="false">
<b>Try to Drag and Drop Text Here :</b> <input type="text" name="txt" id="txtname" />
</body>
</html>
Live Demo

For live demo try to select some text drag and drop in textbox

Try to Drag and Drop Text Here :

If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

6 comments :

Rashmi said...

how to send sms on mobile using asp.net web pages?

Anonymous said...

how to add tab using asp.net web pages?

Unknown said...

how to send sms in asp.net Plz tell me ?

sankarssn.21@gmail.com said...

this is not the right way to hadle this drag and drop problem, why because in this scenario we can drag a text from next browser tab and drop here

sankarssn.21@gmail.com said...

add this two attributes in the input textbox

'onDrop' => "blur();return false;",
'onpaste' => "return false"
this will avoid the drop and paste in textbox

Anonymous said...

drop text from outside browser not blocked with this

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.