asp:textbox select all text by click button and copy to client clipboard

javascript copy to clipboard clipboard copy
jquery copy to clipboard
javascript copy text to clipboard without select
asp net clipboard settext
hyperlink to copy text to clipboard
bootstrap copy to clipboard
chrome copy to clipboard

Is there any way to select all text within a multiline asp:textbox and copy it to client clipboard by clicking a button, using c#?

Thank you in advance.

I think @Denis Wessels answer was great but used plain textarea instead of asp:TextBox, therefore I want to write my own that includes asp:TextBox control.

Consider you have a multi-line text area with asp:TextBox server control and a button to copy content into clipboard:

<asp:TextBox ID="TextArea" runat="server" TextMode="MultiLine">
<button id="copy">Copy to Clipboard</button>

Use jQuery and a JS function similar to this:

<script type="text/javascript">
$(document).ready(function () {
        $("#copy").click(function() {
            // use ASP .NET ClientID if you don't sure
            // for ASP .NET 4.0 and above, set your ClientID with static mode
            var textarea = "<%= TextArea.ClientID %>"; 
            $(textarea).focus(); // set focus to this element first

function copyToClipboard(elem)
    var result;
    var target = elem;
    startPoint = elem.selectionStart;
    endPoint = elem.selectionEnd;

    var currentFocus = document.activeElement;
    target.setSelectionRange(0, target.value.length);

        // this may won't work on Safari
        result = document.execCommand("copy");
    catch (e)
        return alert("Copy to clipboard failed: " + e);

    // returning original focus
    if (currentFocus && typeof currentFocus.focus === "function") {

    elem.setSelectionRange(startPoint, endPoint);

    return result;

Reference with minor changes:,

Note that for ASP .NET 4 and above you can set static ClientID:

<asp:TextBox ID="TextArea" runat="server" TextMode="MultiLine" ClientID="TextArea" ClientIDMode="Static">

thus you can use $("#TextArea") directly rather than $("<%= TextArea.ClientID %>").

asp:textbox select all text by click button and copy to client clipboard, Is there any way to select all text within a multiline asp:textbox and copy it to client clipboard by clicking a button, using c#?. Thank you in  Copying to the clipboard is a tricky task to do in Javascript in terms of browser compatibility. The best way to do it is using a small flash. It will work on every browser. You can check it in this article. Here's how to do it for Internet Explorer: function copy (str) { //for IE ONLY! window.clipboardData.setData('Text',str); }

You can use document.execCommand("copy"); just be aware that this is supported by new browsers mostly and as far as I know there is no support for Safari:

 <head runat="server">
    <script src=""></script>
    <script type="text/javascript">
        $(function () {
            $("#btnCopy").click(function () {
                var id = "#" + "<%= txtText.ClientID %>";
                try {
                catch (e) {
                    alert('Copy operation failed');
    <form id="form1" runat="server">
        <asp:TextBox ID="txtText" runat="server" Text="Some sample text to copy"></asp:TextBox>
        <button id="btnCopy">Copy</button>

Tested and works with the following browsers:

  1. IE 11 and up
  2. Google Chrome 51.0.2704.84
  3. Firefox 43.0.1

copy text into clipboard on button click, Can any one please tell me how can i copy data into clipboard on type="text/​javascript"> function Select(ID) { var control = document. /copy-highlighted-text-​ Javascript don't usually have access to the clipboard of the client due to security reasons. As of 2016, you can now copy text to the clipboard in most browsers because most browsers have the ability to programmatically copy a selection of text to the clipboard using document.execCommand("copy") that works off a selection.

You can use this class: System.Windows.Forms.Clipboard.SetText(..) <= Sets the text to clipboard, Inside SetText(), you put textbox.Text to get the text from the multiline textbox.

Copy to clipboard from FreeTextBox, However I want to copy from a FreeTextBox which is a server side getElementById("myInput") /* Select the text field */; /* Copy the text inside the text field The button used to copy the text --> <button onclick="​myFunction()">Copy The clipboard is on the client machine not the server. Click on the button to copy the text from the text field.

function copyToClipboard(element) {
  var $temp = $("<input>");
<link href='' rel='stylesheet' type='text/css'>
<script src=""></script>

  <p id="p1">Hello, I'm TEXT 1</p>
  <p id="p2">Hi, I'm the 2nd TEXT</p><br/>

  <button onclick="copyToClipboard('#p1')">Copy TEXT 1</button>
  <button onclick="copyToClipboard('#p2')">Copy TEXT 2</button>

  <br/><br/><input type="text" id="" placeholder="TEST it here;)" />

Pro ADO.NET Data Services: Working with RESTful Data, Note the relationships between the Customer entity and the other entities: Right-click the CustomerDataService. svc host file in the web site, and select Copy this URI to the clipboard for the next step in this exercise. Try to query the service, retrieving all customers whose last name contains the text Select the ASP. I need a button to copy text from a text box to the clipboard I have a text box already populated with text, and a button. I want the button click to copy the contents of the text box to the client's clipboard. I did a Google search and came up with two possible methods, but I can't get either to work.

Copy Paste the Text of a Textbox to Clipboard & Clipboard to , how to create copy and paste button in win forms. Or Copying user input from one Duration: 4:34 Posted: Aug 10, 2019 Of course, you can also select the text in a textbox by calling its select function directly through client-side code. For instance, my blog entry Select a textbox's text on focus using jQuery shows how to write a bit of JavaScript so that a textbox's text is automatically selected whenever the textbox receives focus.

TextBoxBase.SelectAll Method (System.Windows.Forms), asp:textbox select all text by click button and copy to client clipboard. Is there any way to select all text within a multiline asp:textbox and copy it to client clipboard  I have had to dive into this in the past and how I managed to make it work is, when the user tries to paste, put the focus to an invisible* textarea, and then read the text out of it. Similarly, to copy you can select a range within the document and then queue a Ctrl+C on the document object.

Auto focus on the first TextBox and tab on the Enter key, If no text is selected, a call is made to the SelectAll method before copying the contents of the control to the Clipboard. This example requires that a TextBox has​  We only fill the ClipBoard with the TextBox's text and let the user control the pasting. For example, the user clicks the Button to copy the data, click a word document and press Ctrl+V to paste the data. private void button1_Click(object sender, EventArgs e) { Clipboard.SetData(DataFormats.Text, textBox1.Text); } 2.