0

I am trying to copy the text in clip board inside the repeater but it's not copying.

Below is what I have tried so far.

protected void rptCopy_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e) {
    if (e.CommandName == "Copy") {
        System.Web.UI.WebControls.LinkButton btnCopy = (LinkButton) rptQuestResponseDtl.Items[0].FindControl("lnkCopy");
        System.Web.UI.WebControls.Label txtMsg = (Label) rptQuestResponseDtl.Items[0].FindControl("lblComment");
        txtMsg.Focus();

        btnCopy.Attributes.Add("onclick", "function copyClipboard(){ CopiedTxt = document.selection.createRange();CopiedTxt.execCommand('Copy'); }");
    }
}
Suprabhat Biswal
  • 2,688
  • 1
  • 16
  • 25
Daniel Stephen
  • 209
  • 3
  • 9
  • Guys please reply ASAP. – Daniel Stephen Aug 23 '18 at 07:08
  • Possible duplicate of [Click button copy to clipboard using jQuery](https://stackoverflow.com/questions/22581345/click-button-copy-to-clipboard-using-jquery) – VDWWD Aug 23 '18 at 07:12
  • this is inside the repeater control – Daniel Stephen Aug 23 '18 at 07:19
  • That does not matter. The copy to clipboard action is front-end, not back-end. Yo are adding the code for copying to a Repeater Button in `rptCopy_ItemCommand`, but the copy itself is not triggered there, nor could it be. – VDWWD Aug 23 '18 at 07:27

1 Answers1

0

should the onclick event be onclientclick like btnCopy.Attributes.Add("onclientclick",... ? Also you defined the function copyClipboard but never called it like copyClipboard()... My recommendation is define function in JS file, include it in your ASPX page and then use clientclick event to call the function

rt2800
  • 2,952
  • 2
  • 17
  • 26
  • I have used both the clicks. ( onclick and onclientclick) it is not working. It is fetching the value from the text. but it is not copying?? :( – Daniel Stephen Aug 23 '18 at 07:26