how to copy contents of literal to clipboard via button on a page?

K

Keith G Hicks

asp.net 2.0

Well until I started looking for how to do this I figured it would be very
easy and lots of information out there. Maybe I'm not looking in the right
places.

I have some code in VB that's creating a list of names and populating a
literal control on the page. I'd like to put a button on the page that let's
the user copy the contents of the literal to the clipboard. As I write this
I'm thinking this probably needs to be client side JS instead of serverside
VB. I'm not very familiar yet with JS so any help anyone can give me would
be greatly appreciated.

I found this but have no idea how to implement it into my page markup.
Please assume I'm in about 1st grade when it comes to JS.

window.fCopyToClipboard = function(rSource){ rSource.select()
if(window.clipboardData){ var r=clipboardData.setData('Text',rSource.value);
return 1; } else return 0 }

the above code is from this site:
http://www.esqsoft.com/javascript-help/how-to-select-html-input-and-copy-to-
clipboard.htm

I assume it needs to fit into here somehow but I don't know the details:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2"
Runat="Server">
<script language="javascript" type="text/javascript">
<!--



// -->
</script>

<br />
Click the radio button of the list you want to create and then click the
"Create
List" button.<br />
<br />
You can select all the itmes in the list and copy/paste it to wherever
you need
it.
</asp:Content>


The ID of my literal control is: "ltrlStudentList"


Thanks,

Keith
 

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

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top