Copy To Clipboard Not Working

W

Wayne Wengert

I am trying to copy the text from a textbox to the clipboard. I saw some
code posted earlier for Pasting from the clipboard so I modified it for copy
but it is not working (see code below). When I click on the
btnCopyToClipboard I can see some processing going on but the text from the
textbox is not being put on the clipboard?

Thoughts or suggestions?

Wayne


====================================
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then

btnCopyToClipboard.Attributes.Add("onclick", "CopyIt();return false;")

Page.RegisterClientScriptBlock("copyroutine", _

"<script>function CopyIt()" & _

"{document.all.txtHidden.focus();" & _

"document.execCommand('copy');}</script>")

End If

End Sub
 
W

Wayne Wengert

After thinking about this code (I know very little javascript) and googling
for ideas I am pretty sure the problem is with the

"{document.all.txtHidden.focus();"

phrase. I suspect that the code needs to be changed to something that
actually selects the text in that text box instead of just giving it focus.
I am going to experiment with "InnerHTML" to see what happens.

Wayne
 
W

Wayne Wengert

I just re-posted this over in the dotnet.languages.jscript forum - I didn't
have that on my list before.

Wayne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top