Share Your Source Code or Article

Do you have source code, articles, tutorials, web links, and books to share? You can write your own content here. You can even have your own blog.

Submit now...

Database Programming Made Easy

This tutorial will teach you step by step on how to connect and manipulate database. If you'd like to suggest a tutorial please write a comment at the bottom of this article.

Read more...

Hire Us to Do Your Work

Do you want a customized system? Do you want to setup your own website to do business? Then we are here to help you in your programming needs.

Read more...

Search

Disable Right Click and Ctrl Keys in ASP.Net
planetsourcecode's picture
Language: .NET
Category: Miscellaneous

We can easily disable right click and control keys in asp.net.In come circumstances.We want to disable the right click so that the user can not copy from or to the asp.net web page.In most of the web application it can be use in any possible condition.
for doing this we have two possible ways:

1). Using asp.net method, which is used when we don't want to show message to the user

  1. <asp:TextBox ID="TextBox1" runat="server"
  2. oncopy="return false"
  3. onpaste="return false"
  4. oncut="return false">
  5. </asp:TextBox>

In this we are making "oncopy","onpaste","oncut" we used "return false"

2). Using JavaScript, which will provide a message to the user(alert message)

for doing this simply add java script into the head section of the web page where we want to restrict the user form the specified keys

  1. <head runat="server">
  2. <title>Untitled Page</title>
  3. <script language="javascript">
  4. function DisableRightClick(event)
  5. {
  6. //For mouse right click
  7. if (event.button==2)
  8. {
  9. alert("Right Clicking not allowed!");
  10. }
  11. }
  12. function DisableCtrlKey(e)
  13. {
  14. var code = (document.all) ? event.keyCode:e.which;
  15. var message = "Ctrl key functionality is disabled!";
  16. // look for CTRL key press
  17. if (parseInt(code)==17)
  18. {
  19. alert(message);
  20. window.event.returnValue = false;
  21. }
  22. }
  23. </script>
  24. </head>

Note: you can place this function to MASTER PAGE, if we want this into many different pages

Now we have to call this function into our pages, using this coding

  1. <body>
  2. <form id="form1" runat="server">
  3. <div>
  4. <strong>
  5. Right click disabled</strong> textbox
  6. <br />
  7. <asp:TextBox ID="TextBoxCopy" runat="server"
  8. onMouseDown="DisableRightClick(event)">
  9. </asp:TextBox><br />
  10. <br />
  11. <strong>Ctrl key </strong>disabled<br />
  12. <asp:TextBox ID="TextBox2" runat="server"
  13. onKeyDown="return DisableCtrlKey(event)">
  14. </asp:TextBox><br />
  15. <br />
  16. Another method to disable<strong> Cut,Copy and paste
  17. </strong>in textbox<br />
  18. <br />
  19. <asp:TextBox ID="TextBox1" runat="server"
  20. oncopy="return false"
  21. onpaste="return false"
  22. oncut="return false">
  23. </asp:TextBox>
  24. </form>
  25. </body>

About the author:

PlanetSourceCode.in is a place for all developer providing free source codes, articles, complete projects,complete application in PHP, C/C++, Javascript, Visual Basic, Cobol, Pascal, ASP/VBScript, AJAX, SQL, Perl, Python, Ruby, Mobile Development

0
Your rating: None



what is the function of...

In this code funtion ParseInt(code)==17 is used.
From this what is the value for 17.
What it should be returned..?

Re: What is the function of...

1) 17 == CTRL Key

2) True / False -- It is checking the number for every key that is pressed and if CTRL is pressed then the warning pops up...that is if you set it up correctly.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <java>, <java5>, <javascript>, <mysql>, <php>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • You may use [inline:xx] tags to display uploaded files or images inline.
  • Links to specified hosts will have a rel="nofollow" added to them.

  • You may insert videos with [video:URL]

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.

Step by Step Java Tutorial

In this tutorial you will learn how to program with Java. It has a rich of information to be educated well with Java.

Read more...

Do You Have Question?

Do you have any question related to computer programming? Visit our forum and post new topic on the category you like. Be gentle when asking a question.

Ask now...

Point of Sale

Point of Sale is very useful especially for supermarkets or restaurants. I have included a barcode scanner in this program. Please check it out.

Read more...