Results 1 to 6 of 6

Thread: use clipboard in asp.net

  1. #1

    Thread Starter
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Resolved use clipboard in asp.net

    Hello
    I'm trying to use the clipboard class in my asp.net project.
    But all documentation I have found on the subject requires the use of the system.windows.forms class.

    From a sql-query I generate a ;-separated text that I display in a textbox. I want to have a button "copy" that copies the content of the textbox into the clipboard so that the user can past it in a document, like notepad.

    Is this possible?

    Thanks
    Anders
    Last edited by onerrorgoto; Sep 22nd, 2004 at 01:38 AM.
    Onerrorgoto

    Dont be to optimistic, the light at the end of the tunnel might be a train

  2. #2
    Banished Cander's Avatar
    Join Date
    Dec 2000
    Location
    Why do you care?
    Posts
    6,913
    No. The server and client architecture of web apps do NOT work like that.
    Stack Overflow
    See the features of Visual Studio 2010 and C# 4.0: The 10-4 show on Channel9

  3. #3
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Cander's right really, i mean, not exactly right, but close...

    you can copy to clipboard using javascript, if the user's browser allows it. And so its only useful when the user accepts that he must allow your webpage access to your computer.

    IE running on XP with Sp2 will notify the user the webpage is trying to access resources on your computer using active content.

    And other browsers have their own quirks.

    http://www.experts-exchange.com/Web/..._20233392.html

    If you go to that page, and find the accepted answer by 'mplungjan' (ignore the signup to see solution, just scroll past the middle advertising), you will see he shows a javascript function which automatically copies a selected value from a listbox to your clipboard.

    Throw his entire html code into a blank html file... run it in IE, when you select A, 'Alpha' gets copied to your clipboard, which you can verify by opening notepad, and right-clicking and selecting PASTE.

    Cander is still of course right, its an answer, but its pretty kludgy because of how webpages are meant to be limited to access to your local machine.

  4. #4

    Thread Starter
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Thumbs up Thanks

    Thank you.
    No. The server and client architecture of web apps do NOT work like that.
    Not the answer I wanted But true.


    and the working kludgy solution.
    you can copy to clipboard using javascript, if the user's browser allows it. And so its only useful when the user accepts that he must allow your webpage access to your computer.
    I'll have to talk to the security-deparment since its an internal app, maybe give them a Double chocolate chip cake to make them more friendly.

    Thanks again
    Onerrorgoto

    Dont be to optimistic, the light at the end of the tunnel might be a train

  5. #5

    Thread Starter
    Hyperactive Member onerrorgoto's Avatar
    Join Date
    Aug 1999
    Location
    Sweden
    Posts
    330

    Unhappy Sorry nemaroller

    Sorry, its the same code as nemaroller posted.

    Check out this
    Htmlgoodies javascript

    I found it on htmlgoodies, its works in IE4 ->

    This effect requires the use of a command available only in IE 4.0 or better,
    Code:
    <SCRIPT LANGUAGE="JavaScript">
    
    function ClipBoard() 
    {
    holdtext.innerText = copytext.innerText;
    Copied = holdtext.createTextRange();
    Copied.execCommand("Copy");
    }
    
    </SCRIPT> 
    
    <SPAN ID="copytext" STYLE="height:150;width:162;background-color:pink">
    This text will be copied onto the clipboard when you click the button below. Try it!
    </SPAN> 
    <TEXTAREA ID="holdtext" STYLE="display:none;">
    </TEXTAREA>
    <BUTTON onClick="ClipBoard();">Copy to Clipboard</BUTTON>
    Last edited by onerrorgoto; Sep 22nd, 2004 at 06:45 AM.
    Onerrorgoto

    Dont be to optimistic, the light at the end of the tunnel might be a train

  6. #6
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704

    Re: A better solution (my opinion)

    Originally posted by onerrorgoto
    [B]Check out this
    Htmlgoodies javascript

    I found it on htmlgoodies, its works in IE4 ->
    That code is no different from what i posted, both use the exec copy command. IE6 sp2 still actively blocks it by default, requiring user to explicitly allow it. So it doesn't work out of the box.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width