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

    Textbox text in clipboard

    Hi,

    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="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title></title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    <asp:TextBox ID="TextBox1" runat="server" BorderStyle="Solid"></asp:TextBox>
    <asp:Button ID="ButtonCopy" runat="server" Text="Copy to clipboard"
    onclick="ButtonCopy_Click" />
    </div>
    </form>
    </body>
    </html>

    Code - behind (C#) :

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

    void copytoclipboard()
    {
    if (TextBox1.Text.Length > 0)
    {
    Clipboard.SetText(TextBox1.Text);
    }
    }

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

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

    Hope this is what you are looking for.

    Regards,
    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="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.11.3.min.js"></script>


    Hope this will help you.

    Regards,
    Shashikant Gurav
    shashikantgurav22@gmail.com


Sign In to post your comments