Disable Drag and Drop for a Web Control or an Entire Web Form

In the real world, sometimes developers need to restrict a basic facility, like cut, copy and paste either on an entire web page or a specific control. But after doing this, the end user can fill in the control like a TextBox without typing a character by dragging & dropping. So you have also to block the drag and drop facility in the entire Web Form or Web Control.

You will need some easy way to stop these kinds of facilities in the page or web control.

To explain such implementation, I will use the following procedure.

Step 1

Create an ASP.Net Empty Website named "My Project".

empty website

Step 2

Add a new web form named "Default.aspx" to it.

web form

Step 3

Add 2 "TextBox" controls in the page named "Default.aspx".

TextBox

Step 4

  1. In the TextBox: To block the drag & drop facility in both "TextBox" Controls, use the following syntax in both controls.

    Syntax: ondrag= “return false”; ondrop= “return false”;

    In the TextBox

  2. In an entire page: To block the drag & drop facility in the entire page, use the following syntax in the "body" tag.

    Syntax: ondrag= “return false”; ondrop= “return false”;

    In a Whole Page
Conclusion

In this article, I have described how to block the use of drag & drop in an entire page or just a web control. I hope it will be beneficial for you.

Up Next
    Ebook Download
    View all
    Learn
    View all