Search
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
<asp:TextBox ID="TextBox1" runat="server" oncopy="return false" onpaste="return false" oncut="return false"> </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
<head runat="server"> <title>Untitled Page</title> <script language="javascript"> function DisableRightClick(event) { //For mouse right click if (event.button==2) { alert("Right Clicking not allowed!"); } } function DisableCtrlKey(e) { var code = (document.all) ? event.keyCode:e.which; var message = "Ctrl key functionality is disabled!"; // look for CTRL key press if (parseInt(code)==17) { alert(message); window.event.returnValue = false; } } </script> </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
<body> <form id="form1" runat="server"> <div> <strong> Right click disabled</strong> textbox <br /> <asp:TextBox ID="TextBoxCopy" runat="server" onMouseDown="DisableRightClick(event)"> </asp:TextBox><br /> <br /> <strong>Ctrl key </strong>disabled<br /> <asp:TextBox ID="TextBox2" runat="server" onKeyDown="return DisableCtrlKey(event)"> </asp:TextBox><br /> <br /> Another method to disable<strong> Cut,Copy and paste </strong>in textbox<br /> <br /> <asp:TextBox ID="TextBox1" runat="server" oncopy="return false" onpaste="return false" oncut="return false"> </asp:TextBox> </form> </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
- 658 reads



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