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

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Disable copy paste in textbox without Javascript

Posted By:      Posted Date: September 21, 2010    Points: 0   Category :ASP.Net



Can you somebody help me in disabling copy paste in the textbox without using Javascript for an web application?




View Complete Post

More Related Resource Links

disable COPY/Paste function on a textbox

Hi, I want to make disable COPY/Paste function on a textbox. DO u know how to do it if so please let me know asap? And it is required to be done at client side. The text box can be HTML or ASP:TextBox. Please reply asap.

Disable "Paste" lable on read only textbox.

Hi, I am new to C# .NET. I am facing very small problem. i.e. I made a text box with readonly option. Now this text box is not allowing to paste,ok its working fine. But when i give mouse right click paste lable is enable. Can you guide me how to disable this lable. With Regards Srinubabu

Mission Impossible? Use Javascript to Disable a Multi-Line Rich Text Field


Hey Community,

Here's a tough one that I have struggled with and so far have not been able to find an answer for - how do you use Javascript to disable a multi-line rich text field.  I have customized a SP Edit form by adding a CEWP.  In the CEWP I have added the Javascript below (only a partial code sample provided) to disable several fields in the form.  The code works fine for single line text fields but it does not work for multi-line rich text fields.  Any suggestions?

<script language="javascript">
//This runs the function when the form first loads

//This locks the fields the users should not modify
function lockFields()
  var theInputTFTitle = getTagFromIdentifierAndTitle("Input","TextField","Title");
  theInputTFTitle.readOnly = true;
  theInputTFTitle.style.color = 'gray';
  //alert(" Value: " + theInputTFTitle.value);//for testing

   var theInputDDLReplyStatus = getTagFromIdentifierAndTitle("select","DropDownChoice","Reply Status");
  theInputDDLReplyStatus.disabled = true;
  //alert(" Value: " + theInputDDLReplyStatus.value);//for testing

  var theInpu

Issues with multiline textbox, javascript and IE


Hi All,

i have a requirement to embolden/italicise the selected  text in a textbox. the way it is implemented as is by using a js function which inserts <b> and </b> tags at the start and end of the selected text  for bold, and similarly <i> and </i> tags at the start and end of the selected text  for italics.

here is the code in c# (to add attributes to link buttons)

lkbBold.Attributes.Add("onclick", "AddHTMLTags('" + txtTitle.ClientID + "', 'B'); return false;");
lkbItalic.Attributes.Add("onclick", "AddHTMLTags('" + txtTitle.ClientID + "', 'I'); return false;");

the txtTitle is the id of the text box, which contains the selected text to be emboldend.

and here's the javascript method

function AddHTMLTags(textBoxId, format)
  var textComponent = document.getElementById(textBoxId);
  var selectedText;
  var textToReplace; 
  var content = document.getElementById(textBoxId).value;
  var content1 ;
  var content2 ;
  var newContent; 
      // For IE 
      if (document.selection != undefined)
        var len =  document.selection.createRange().text.length;
        var myrange

How to disable textbox causing validation?

Hello I was running into a strange problem: If I left a textbox blank (in some instances) the textbox would not give up the focus (I could not even close the form).  I learnt later that this was because the text in the textbox was causing validation to fail.  I would have to type in some value (Satisfy validation) before i could close the form. This is problematic for me and I don't want the textbox to behave this way (I do not awnt front end validation).  I desire to have validation done ONLY on the back end.     I thought that I could solve this problem by changing the 'CausesValidation' property in the textbox to false.  This worked!  However it introduced a new problem.  The binding no longer worked on the Textbox.  That is, whatever value I typed in the textbox would not make it to the data set. What is the correct way in solving this problem???  I want validation to be shut off however I still (obviously) need to keep binding in tact...      

Javascript code to copy selected dropdown item to clipboard

Does anyone know how I can do this to get the text onto the clipboard?  <input id="Copy" type="button" value="Copy Url" runat="server" onclick="copy();" style="vertical-align: top;" visible="false"/><script type="text/javascript"> function copy() { var sel = document.getElementById("DropDownList1"); var text = sel.options[sel.selectedIndex].value; ??? } </script> </body>  

Button to copy selected item in dropdown to textbox

Hi, I found this bit of code which I tried and it isn't working. I just want to place a button next to a dropdown, and when clicked, the selected item in the dropdown will put into another textbox. <head><title>Untitled</title></head><body><script type="text/javascript">function copy() {var sel = document.getElementById("names");var text = sel.options.value;var out = document.getElementById("output");out.value += text+"\n";}</script> <select id="names"><option>Product One</option><option>Product Two</option><option>Product Three</option><option>Product Four</option></select><input type="button" onclick="copy()" value="Copy"><textarea id="output"></textarea> </body></html>   I saved this as a file and opened it in IE to test and nothing went into the textarea. Also i tried it in Firefox and the textarea said undefined each time I click the button. Can someone help to get this working?

Copy/paste broken in SSMS 2008 R2

After uninstalling an SSMS addin (from Red Gate), my copy/paste functionality in SSMS broke -- don't know if it's correlated.  As documented in the bug https://connect.microsoft.com/SQLServer/feedback/details/126743/copy-paste-stop-working-in-sql-2005 it seems that paste is working fine, because it works when I copy from other programs.  When I paste from SSMS, though, I can't paste anywhere.  It's as though SSMS clears the clipboard and that's all she wrote. Anyone else seeing this problem? -matthew

Copy/Paste Fails in Management Studio

After opening Management Studio and doing some editing it is possible to copy/paste things in the query editor. After a while (working in another app) I come back to Management Studio and I can't copy/paste anything anymore. If I try to copy from the results window I get an error message that the clipboard operation did not succeed. If I try to copy from the query editor window it just doesn't copy. I can copy/paste in other apps without a problem.   I have seen this problem described in other forums so I'm not alone but I have 3 other computers where this problem does not occur. The one machine with the problem is hyper-threading. I wonder .... Any other ideas? It is not the clipboard getting full but I can't rule out much else.

paste image from clipboard using javascript

Hi all, How do we paste an image from clipboard into a custom rich text editor using javascript? (ctrl+c and ctrl+v or a snapshot) Please do share your thoughts! Thanks!  

Javascript to update value in Textbox

Hi I have a javascript file, which creates a calendar picker. This file is used through out the application and is a piece of code that I have to use because my .Net application is part of another application which uses this piece of JavaScript code.Anyhow, with the calendar picker I can save the date into a textbox, but the problem that I have is the format. Unfortunately, I cannot change the calendar picker code because this will affect other parts of the application. Therefore, what I am looking to do is to reformat the date on the textbox control. This I can do but only when I use the javascript event onfocus.Now, my question is this, is there away in javascript or with jquery that when a value enters into a textbox that this value is then reformatted to the format I want without postback or clicking on the textbox?Thanks

Problem with JavaScript on Textbox

 I have a textbox which is populated by an external javascript file which I cannot alter without affecting another part of the system. What I would like to do is once this textbox has a value to do something with it. The javascript that I want to use is fine, but it won't automatically when a value has populated it i.e. onchange. It will work when the event is onfocus. Is there away in which I can automatically fire off my javascript event when a value has entered the textbox from another piece of javascript code?  

Image copy/Paste on a asp.net webpage

  Hi All,            I need a help, in my project I have a requirement, which is I have to copy image from MS-Word and paste it on webpage directly. So that copied image should be display on webpage and save into server automatically. It can be possible using windows applications., but now the same functionality has to implement in asp.net web applications. Any help much appreciated. J Hint:  using javascript Clipboard functionality we may achieve it, but could get correct solution for this . :( Thanks, Naidu 

problem with javascript in multiline textbox

 I am setting Maxlength of a textbox using javascript. Take maxlegth as 100.As we know Enter key is taking two char space. But i want to avoid this. i.e. if i press enter key after 96th char it should allow me to enter four more char where now it is allowing only 98. This is wat i am using  function textboxMultilineMaxNumber(txt,maxLen) { try { if(txt.value.length > (maxLen-1)) return false; } } catch(e){ } }

How to conditionally Enable/Disable Button control using JavaScript ?

hi all... i have a Button control & a TextBox control on my web page. The Button control is initially Disabled. I want that while typing into TextBox, when the length of the contents of TextBox reaches to 12 (i.e. when i type 12th character), the Button Control should be Enabled & if the length again comes down to less than 12, the Button control should again be Disabled... How can i do this using JavaScript...?? Does anyone know how to do this...?? Please help. It's urgent... Thanx in advance to all posts !

linebreak in textbox using javascript

I want to assign a textvalue with linebreaks to a textbox control using javascript.I tried (\n):hlResetStyle.Attributes.Add("onclick", "javascript:document.getElementById('" + CSS.ClientID + "').value='#progress{color:#000;width:500px;height:30px;padding:0px;clear:both;}\n\n\n#progress ul{list-style:none;padding:0px;margin: auto;display:block;}';")and tried (<br/>)hlResetStyle.Attributes.Add("onclick", "javascript:document.getElementById('" + CSS.ClientID + "').value='#progress{color:#000;width:500px;height:30px;padding:0px;clear:both;}<br/><br/><br/><br/>#progress ul{list-style:none;padding:0px;margin: auto;display:block;}';")But without luck....How to do it?

Remove Word Style once copy and paste content to Rich text Editor in sharepoint 2010

Hi Guys, I have page layout for Users to add content for Page.I have site column for page content on field type HTML with Richtextmode="FUll Html". Now when user cut and paste content from Word document in this Field it carry word document style. how can i control this content on Page layout with CSS. Please adviseThanks Ron
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

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