Copy text to clipboard using Zero Clipboard in asp.net

asp.net, c#, copy, web-applications, zeroclipboard

Solution

<html>
<body>
<button id="copy-button" data-clipboard-text="Copy Me!" title="Click to copy me.">
Copy to Clipboard</button>
<script src="ZeroClipboard.js"></script>
<script src="main.js"></script>
</body>
</html>

//In Main.js file
// main.js
var clip = new ZeroClipboard( document.getElementById("copy-button"), {
moviePath: "/path/to/ZeroClipboard.swf"
} );

clip.on( 'load', function(client) {
// alert( "movie is loaded" );
} );

clip.on( 'complete', function(client, args) {
this.style.display = 'none'; // "this" is the element that was clicked
alert("Copied text to clipboard: " + args.text );
} );

clip.on( 'mouseover', function(client) {
// alert("mouse over");
} );

clip.on( 'mouseout', function(client) {
// alert("mouse out");
} );

clip.on( 'mousedown', function(client) {

// alert("mouse down");
} );

clip.on( 'mouseup', function(client) {
// alert("mouse up");
} );

Problem

I am trying to use Zero *Clipboard* to copy text from Textbox to Clipboard when client clicks a Button. I am trying this for many days but no luck to make this work. In Scenario, i have one Textbox which render data from the Database. I have one Button which when client clicks should copy text of the Textbox. I have tried following but its not working. Some help will be appreciated. ``` <script type="text/javascript" src="/Scripts/ZeroClipboard.js"></script> <script type="text/javascript"> ZeroClipboard.setMoviePath('/Scripts/ZeroClipboard.swf'); </script> <script> function test() { ZeroClipboard.setMoviePath('/Scripts/ZeroClipboard.swf'); //create client var clip = new ZeroClipboard.Client(); //event clip.addEventListener('mousedown', function () { clip.setText(document.getElementById('TextBox2').value); }); clip.addEventListener('complete', function (client, text) { alert('copied: ' + text); }); //glue it to the button clip.glue('d_clip_button'); } </script> <asp:TextBox ID="TextBox2" runat="server" BorderStyle="None" Enabled="False" Font-Size="Medium" ForeColor="Black" Width="213px"></asp:TextBox> &nbsp;<asp:Button ID="d_clip_button" runat="server" Text="Copy" OnClientClick="javascript:test();" /> ```

Original source