You must Sign In to post a response.
  • Category: JavaScript

    Textbox text in clipboard


    I want to copy my textbox value in clip board. I tried using window.clipboardData.setData(); but it is saying that window.clipboard is undefined. should I include any Js or any supporting files?
  • #763021
    Hello Anjali,

    Refer the below code :

    <html xmlns="" >
    <head runat="server">
    <form id="form1" runat="server">
    <asp:TextBox ID="TextBox1" runat="server" BorderStyle="Solid"></asp:TextBox>
    <asp:Button ID="ButtonCopy" runat="server" Text="Copy to clipboard"
    onclick="ButtonCopy_Click" />

    Code - behind (C#) :

    using System.Windows.Forms;
    using System.Threading;

    void copytoclipboard()
    if (TextBox1.Text.Length > 0)

    protected void ButtonCopy_Click(object sender, EventArgs e)
    Thread myth;
    myth = new Thread(new System.Threading.ThreadStart(copytoclipboard));
    myth.ApartmentState = ApartmentState.STA;

    See the attached image. It's an output i have got using above mentioned code.

    Hope this is what you are looking for.

    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"

    Delete Attachment

  • #764146
    Hi Anjali,

    Yes setData is working with me as follows:

    window.clipboardData.setData('Text', 'Textbox text');

    But I have following js included in my program:
    <script src=""></script>

    Hope this will help you.

    Shashikant Gurav

Sign In to post your comments