.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> ASP.Net >> Post New QuestionBookmark and Share Subscribe to Forum

How to restrict user to (ctrl+v) option for a text box..?

Posted By: susant     Posted Date: March 17, 2009    Points:2   Category :ASP.Net
Hi All

How to restrict user to (ctrl+v) option for a text box..

Note : ASP.Net + C#

ThanX and Regards
susant

Responses
Author: Rahul             
Posted Date: March 17, 2009     Points: 5   

Hi Susant,
the easy way is like this

<asp:TextBox ID="TextBox1" runat="server" onpaste="return false" oncut="return false">
</asp:TextBox>


another way is using javascript


function noCopyMouse(e) {
var isRight = (e.button) ? (e.button == 2) : (e.which == 3);

if(isRight) {
alert('You are prompted to type this twice for a reason!');
return false;
}
return true;
}

function noCopyKey(e) {
var forbiddenKeys = new Array('c','x','v');
var keyCode = (e.keyCode) ? e.keyCode : e.which;
var isCtrl;

if(window.event)
isCtrl = e.ctrlKey
else
isCtrl = (window.Event) ? ((e.modifiers & Event.CTRL_MASK) == Event.CTRL_MASK) : false;

if(isCtrl) {
for(i = 0; i < forbiddenKeys.length; i++) {
if(forbiddenKeys[i] == String.fromCharCode(keyCode).toLowerCase()) {
alert('You are prompted to type this twice for a reason!');
return false;
}
}
}
return true;
}

in code behind page_load event

Textbox1.Attributes.Add("onmousedown", "return noCopyMouse(event);")
Textbox1.Attributes.Add("onkeydown", "return noCopyKey(event);")






Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend