Monday, May 12, 2025

Breaking News
>> Securing and encrypt View State and Cookies values  >> Page has one or more controls that do not correspond with   >> “The Controls collection cannot be modified because the control contains code blocks”  >> How to fix "Validation(): Element 'xxxx' is not supported  >> How to create a new session in ASP.NET programmatically  >> MySQL Database Backup using mysqldump command    

Editors Picks

Friday, July 1, 2011

Disable copy paste right click using javascript in asp.net textbox



Disable copy paste right click using javascript in asp.net textbox



1. use this method when u don't want any alerts or message 

<asp:TextBox ID="TextBox3" runat="server"
oncopy="return false"
onpaste="return false"
oncut="return false">
asp:TextBox>


2. If you want to show alerts than use this method instead
Right this javascript function in the head section of aspx page, in this function we are disabling right mouse click and ctrl keys

<head id="Head1" runat="server">
<title>Untitled Pagetitle>
<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>

<body>
<form id="form1" runat="server">
<div>
<strong>
Right click disabledstrong> 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>


No comments :

Post a Comment

Contact Us

Name

Email *

Message *