Solved

Can not copy to Clipboard referencing ASP Text Box - ASP.Net 2.0

Posted on 2007-03-21
2
828 Views
Last Modified: 2008-02-01
Hello,

I have an ASP.Net 2.0 Web Form in which I would like to be able to Copy from an ASP Text Box to the Client Side Clipboard.  From reading similar postings,  I understand this needs to be done using a Client Side Script like JAVA and in fact I've been able to get an example, I copied,  to work.  My issue though is that the example uses an HTML Text Box from which to copy the text.  I want to use a server side asp Text Box because I fill the Text Box in code.  The Text Box is filled with a complete Web Service Class, for the User to Copy... so it's a fair amount of text.  

The Scrip errors when attempting to reference the server side asp Text Box.  I tried a different approach in using Response.Write in the Page On-Load Event to create the Scipt with the Text in it, eliminating the need to refernce the Text Box, but I couldn't figure out how to properly write all the text in a VB Code Module correctly formated for Java Script.  This also winds up creating all this text twice, once in the scipt and once for the Text Box.  So this brings me back to wanting to be able to reference the Text Box.  When the page renders the Script is there and the Text Box Text is there, I just can't seem to reference it.  

In the code below if you replace  TextBox1.value with quoted text it works.  So the HTML button from within the Form Tags can call the Script... the Script just can't reference the text box... even if the
Text Box is and HTML Text Box... it still errors when inside the Form Tags.

Thanks in advance!

<script type="text/javascript">
function ClipBoard()
{
window.clipboardData.setData("Text", TextBox1.value);
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server">Text to copy here</asp:TextBox><br />
        <br />
        <input id="Button1" type="button" value="Copy to Clipboard" onclick="ClipBoard()" />
    </div>
    </form>
</body>
</html>        
0
Comment
Question by:Todd_Sales20-20
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 13

Accepted Solution

by:
jeebukarthikeyan earned 500 total points
ID: 18874452
hi ,

window.clipboardData.setData("Text", TextBox1.value);

change the above script to

window.clipboardData.setData("Text",  document.getElementById('TextBox1').value);

b u d d h a
0
 

Author Comment

by:Todd_Sales20-20
ID: 18878831
Thanks... works great!  Even works within an ASP AJAX UpdatePanel where the I have recently placed the TextBox and Button.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question