0

I have a repeater that will bind data's from the database into the text box and every textbox there's a copy button. What I want is to copy the text from the textbox when the copy button was clicked. Btw, I'm using a visual studio 2008 Web Form. I tried using the Clipboard.SetText but didn't work. Im working now with this.

Code Behind:

Protected Sub rpt_ItemCommand(ByVal source As Object,
                              ByVal e      As System.Web.UI.WebControls.RepeaterCommandEventArgs)
        Handles rpt.ItemCommand
    If e.CommandName = "Copy" Then

        Dim btnCopy As System.Web.UI.WebControls.Button = e.Item.FindControl("btnCopy")
        Dim txtMsg As System.Web.UI.WebControls.TextBox = e.Item.FindControl("txtMessage")
        txtMsg.Focus()

        btnCopy.Attributes.Add("onClientClick", "function copyClipboard(){ CopiedTxt = document.selection.createRange();CopiedTxt.execCommand('Copy'); }")

    End If
End Sub

Hope you can help me. Thanks

eckes
  • 10,103
  • 1
  • 59
  • 71
Chinx
  • 15
  • 1
  • 7

1 Answers1

2

Button control's client-side click event name should onclick.

btnCopy.Attributes.Add("onclick", "alert('button is clicked');");
Win
  • 61,100
  • 13
  • 102
  • 181
  • @Chinx I have no idea how your Javascript is supposed to work. First of all, start with simple Javascript such as `alert('...')`. Then move to complex one. If you get any exception at client side, please post it in your question. – Win Sep 15 '14 at 15:11
  • Hi Win, Im currently working on a work around. The Clipboard.SetText(message), but still dont work. Both on IE and Chrome. I didnt have any error encounter and yet still the same. – Chinx Sep 22 '14 at 16:43
  • [How to copy to the clipboard in JavaScript?](http://stackoverflow.com/questions/400212/how-to-copy-to-the-clipboard-in-javascript) – Win Sep 22 '14 at 17:56
  • I copy text to Clipboard using this function. function copyClipboard() { CopiedTxt = document.selection.createRange(); CopiedTxt.execCommand("Copy"); } – Chinx Sep 22 '14 at 19:16
  • @Chinx Copy to clipboard is not a new thread. Please read [this](http://stackoverflow.com/a/22581382/296861) or Search in SO. – Win Sep 22 '14 at 20:39