Click here to Skip to main content
16,020,519 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I want to copy content from popup page(popup page is aspx page.) My requirement is need add one "Button" on that popup page . When we will click on that button(COPY), All content should copy(For contents Label is used) using ASP.NET C# or Javascript.

Here is my code which is working. But there is one problem in my code. How to achieve this by clicking on Button(Copy) content should copy .

It is working now. But there is one problem i found after testing my application.

Problem is that, I have icons in each row inside gridview . If i clicked on icon, its showing as like popup(Actually its not a popup window, Added as new page). My doubt is, if first time i clicked on COPY button on any rows, its able copy content .But second time while clicking on COPY button in different rows inside gridview, its not copying other content. Its copying old content which i copied earlier.

How to fix this issue, While click on COPY button on any icon in any rows, its copy that rows content data instead of previews/first time copy data/content.
HTML
<pre><input type="button" id="btnCopy"  value="Copy" onclick="window.clipboardData.setData('text', document.getElementById('ltlContentName').innerText);" />


What I have tried:

I tried above code.
<input type="button" id="btnCopy"  value="Copy" onclick="window.clipboardData.setData('text', document.getElementById('ltlTemplateName').innerText);" />
Posted
Updated 20-Jan-23 0:08am
v2

1 solution

Use following function:
JavaScript
function copyToClipboard(sID) {
        var aField = document.getElementById("hiddenField");

        aField.hidden   = false;
        aField.value    = document.getElementById(sID).textContent;
        aField.select();
        document.execCommand("copy");
        alert("Following text has been copied to the clipboard.\n\n" + aField.value);
        aField.hidden = true;
    }


Visit this link for more information
How do I copy to the clipboard in JavaScript? - Stack Overflow[^]
 
Share this answer
 
Comments
kamalsekhar 9-Jan-17 7:50am    
Hi Sunasara,
I am getting this error --> 0x800a138f - JavaScript runtime error: Unable to get property 'textContent' of undefined or null reference. Pls help me

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900