How to copy a string value to clipboard?

Last post 10-01-2008 3:11 AM by CoolBond. 8 replies.

Sort Posts:

  • How to copy a string value to clipboard?

    09-27-2008, 4:32 AM
    • Member
      11 point Member
    • greengrass
    • Member since 06-29-2007, 8:58 PM
    • Posts 48

    Hello,

    I need to be able to copy a string value to the windows clipboard.

    Could anyone suggest how I could do this?

    GG

    Another fine mess I've got myself into.
  • Re: How to copy a string value to clipboard?

    09-27-2008, 8:55 AM
    • Member
      11 point Member
    • greengrass
    • Member since 06-29-2007, 8:58 PM
    • Posts 48

    Anyone? I could sure use some help on this.

    Another fine mess I've got myself into.
  • Re: How to copy a string value to clipboard?

    09-27-2008, 8:59 AM
    • All-Star
      76,039 point All-Star
    • NC01
    • Member since 08-26-2005, 7:33 PM
    • Posts 14,166
    • TrustedFriends-MVPs

    Have you tried Googling for a solution? Try this link: http://dynamic-tools.net/toolbox/copyToClipboard/

    NC...

     

  • Re: How to copy a string value to clipboard?

    09-27-2008, 9:35 AM
    • Member
      11 point Member
    • greengrass
    • Member since 06-29-2007, 8:58 PM
    • Posts 48

    Only for the last two hours! I need to get a value from codebehind (actually the selected item's ID) and pass it to the clipboard. The script you suggested only copies a set text area I believe.

    Another fine mess I've got myself into.
  • Re: How to copy a string value to clipboard?

    09-27-2008, 9:46 AM
    Answer
    • All-Star
      76,039 point All-Star
    • NC01
    • Member since 08-26-2005, 7:33 PM
    • Posts 14,166
    • TrustedFriends-MVPs

    greengrass:

    Only for the last two hours! I need to get a value from codebehind (actually the selected item's ID) and pass it to the clipboard. The script you suggested only copies a set text area I believe.

    Maybe because you never mentioned that you need to get a value from codebehind? You'd have to use AJAX or a PostBack to get the ID as those are the only 2 ways to access the CodeBehind from the client-side. Far too complex and too much code to post a solution here, but check this AJAX link. http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_httprequest_js4

    You would then have to use the script in the link that I previously posted to paste to the Clipboard.

    NC...

     

  • Re: How to copy a string value to clipboard?

    09-27-2008, 9:50 AM
    • Contributor
      2,710 point Contributor
    • CoolBond
    • Member since 10-25-2007, 9:34 AM
    • Country
    • Posts 535
    Hope this will help you....

    " If people criticize you, hurt you, or shout at you,Don't be bothered. Just remember, In every game, audience make the noise, not the players "
  • Re: How to copy a string value to clipboard?

    09-27-2008, 9:52 AM
    • All-Star
      76,039 point All-Star
    • NC01
    • Member since 08-26-2005, 7:33 PM
    • Posts 14,166
    • TrustedFriends-MVPs

    CoolBond:

    I get a "Page not found" error with that link.

    NC...

     

  • Re: How to copy a string value to clipboard?

    10-01-2008, 2:58 AM
    Answer
    Hi greengrass
     
    Just as NC posted, we can Set/Get/Clear users’ clipboard by the JavaScript window.clipboardData object, which only works in Internet Explorer, by the following code:
     
    window.clipboardData.setData("text",value)
    window.clipboardData.getData("text")
    window.clipboardData.clearData("text")
     
    If you need set a code-behind value to user’s clipboard, please pass it to JavaScript variable first, and then, set the value to clipboard. Or you can call the JavaScript from code-behind, just like the following code:
      
    protected void Button1_Click(object sender, EventArgs e)
    {
        string values = "hello world";
        ClientScript.RegisterStartupScript(this.GetType(), "copy", "window.clipboardData.setData('text','"+values+"')", true);
    }
     
     
    Thanks.
     
     

     

    Lance Zhang
  • Re: How to copy a string value to clipboard?

    10-01-2008, 3:11 AM
    Answer
    • Contributor
      2,710 point Contributor
    • CoolBond
    • Member since 10-25-2007, 9:34 AM
    • Country
    • Posts 535

     Hi

    sorry about that. I got a information that it is not safe to copy the web page data into Clipboard in that link.

    Try with this links

    Using ClipBoard in ASP.Net

    Using Clipboard Class in ASP.Net

     

    Hope this will help you

     

    Hope this will help you....

    " If people criticize you, hurt you, or shout at you,Don't be bothered. Just remember, In every game, audience make the noise, not the players "
Page 1 of 1 (9 items)