VERY URGENT: WEB Copy a TextBox's Text to the web users clipboard

hi i have a long string in a textbox on a .net aspx webpage and need to copy this text to the web users clipboard so the user can use it in different applications, can i do this and if so how?
LVL 2
Robinsonx6Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

petmagdyCommented:
Robinsonx6

Are u sure u submitted to the right place? this is the java topic channel
0
Robinsonx6Author Commented:
yeah i assumed because it would need to be done client side i would need to use javascript
0
petmagdyCommented:
no here too, their is other topic for javascript
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Robinsonx6Author Commented:
ok ill get this one closed by the page editor

thanks
0
suprapto45Commented:
Hi,

Check this out. You can simply change the name to your textbox on .net (aspx)
http://gilles.saunier.free.fr/scripts/clipboard.html


Dave
0
suprapto45Commented:
Hi,

Sorry I thought that you want to use simple HTML. If you use .aspx in .NET, you have to declare <script>...</script> within your .aspx file. Unfortunately you must do it manually (the system will not generate it for you).

For example you want to copy the textbox in .aspx to clipboard.

<asp:TextBox id="TextBox1" style="Z-INDEX: 103; LEFT: 304px; POSITION: absolute; TOP: 104px" runat="server"></asp:TextBox>

Add these codes just above your <asp:TextBox...></asp:TextBox>

<script for="Button2" event="onclick">
      document.Form1.TextBox1.focus();      
      document.Form1.TextBox1.select();      
      var oControlRange = document.Form1.TextBox1.createTextRange();                        
      oControlRange.execCommand("copy");    
</script>

And of course that you need to have button with the id="Button2".
Now you can simply press Ctrl+V anywhere and you should get the text on your textbox.

Thanks and I hope that helps.

Best Regards
Dave
0
Robinsonx6Author Commented:
i am assuming that because my form is called banners it is as follows

<script for="Button2" event="onclick">
     document.banners.TextBox1.focus();    
     document.banners.TextBox1.select();    
     var oControlRange = document.banners.TextBox1.createTextRange();                    
     oControlRange.execCommand("copy");    
</script>
0
Robinsonx6Author Commented:
ok im getting an error saying that document.banners.txtLink does not exist or is null?

HeLp please im not very good with javascript

<script for="Button2" event="onclick">
     document.banners.txtLink.focus();    
     document.banners.txtLink.select();    
     var oControlRange = document.banners.txtLink.createTextRange();                    
     oControlRange.execCommand("copy");    
            </script>
            <asp:TextBox id="txtLink" Width="700px" Runat="server" CssClass="Textentry"></asp:TextBox>
            <BR>
            <asp:HyperLink id="hypertest" Runat="server" Target="_blank"></asp:HyperLink>
            <BR>
            <button id=Button2>Copy text 2</button>
0
zzynxSoftware engineerCommented:
Don't know javascript that good neither, but maybe you should define "txtLink" before the <script>  </script> block where you use it:

     <asp:TextBox id="txtLink" Width="700px" Runat="server" CssClass="Textentry"></asp:TextBox>
<script for="Button2" event="onclick">
    document.banners.txtLink.focus();    
    document.banners.txtLink.select();    
    var oControlRange = document.banners.txtLink.createTextRange();                    
    oControlRange.execCommand("copy");    
</script>
     <BR>
     <asp:HyperLink id="hypertest" Runat="server" Target="_blank"></asp:HyperLink>
     <BR>
     <button id=Button2>Copy text 2</button>

Just an idea...
0
Robinsonx6Author Commented:
tried it still didnt work! im still getting document.banners.txtLink does not exist or is null?
any more ideas
0
zzynxSoftware engineerCommented:
Did you already try posting a 20 points question (with an attracting title like "500 points Q" ;°)
in the javascript topic area linking to this Q?
0
suprapto45Commented:
Hi,

Can you post the whole of your .aspx file?

Best Regards
Dave
0
suprapto45Commented:
Oh yes,

Please change your button to the .aspx format and not the simple as <button id=Button2>Copy text 2</button>
0
Robinsonx6Author Commented:
zzynx the answer is no to your comment :-)
0
suprapto45Commented:
Dear Robinsonx6,

Did you manage to make that run? I will be offline very soon.

Regards
Dave
0
Robinsonx6Author Commented:
no i didnt once you use an asp:button the code doesnt get run
0
suprapto45Commented:
Can you post your .aspx for me to look at?
Are these codes within <form>...</form>

Regards
Dave
0
Robinsonx6Author Commented:
the code is within an ascx control file loaded within the form element of the parent aspx page
0
Robinsonx6Author Commented:
<%@ Control Language="c#" AutoEventWireup="false" Codebehind="view.ascx.cs" Inherits="Admin.content.banner.view" TargetSchema="http://schemas.microsoft.com/intellisense/ie5"%>
<asp:panel id="Panel5" Width="100%" HorizontalAlign="Center" Runat="server">
      <asp:Panel id="Panel1" Width="60%" Runat="server" BorderStyle="None" CssClass="pnlcriteria">
            <asp:DataList id="DataListbanners" Runat="server" RepeatColumns="2" RepeatDirection="Horizontal" BorderWidth="0">
                  <ItemTemplate>
                        <table>
                              <tr>
                                    <td>
                                          <asp:Image ImageUrl=' <%# "http://www.3Deja-vu.com/images/banners/" + DataBinder.Eval(Container.DataItem, "Name") %>' Runat=server ID="Image2" />
                                    </td>
                              </tr>
                              <tr>
                                    <td align="center">
                                          <asp:CheckBox EnableViewState=True ID=chkimage OnCheckedChanged=chkselected AutoPostBack=True Text='<%# DataBinder.Eval(Container.DataItem, "Name") %>' Runat=server />
                                    </asp:CheckBox>
                              </tr>
                        </table>
                  </ItemTemplate>
            </asp:DataList>
      </asp:Panel>
      <BR>
      <BR>
      <asp:Panel id="pnlcriteria" Runat="server" CssClass="pnlcriteria">
            <asp:Label id="Label1" Width="80%" CssClass="LabelEntry" runat="server">Please select your chosen banner<br>ensure only one is selected<br> and choose the Resort below.</asp:Label>
            <asp:Label id="lblcriteria" Runat="server" CssClass="LabelEntry">Resort</asp:Label>
            <asp:DropDownList id="ddlresort" Runat="server" CssClass="TextEntry"></asp:DropDownList>
            <BR>
            <asp:Button id="btnCreate" Runat="server" Text="Create Link"></asp:Button>
      </asp:Panel>
      <br>
      <asp:Panel id="pnlbusttl" Runat="server" cssClass="pnltitle">
            <asp:Image id="Image1" Runat="server" ImageUrl="../../images/ttl_linkdetails.gif"></asp:Image>
      </asp:Panel>
      <asp:Panel id="Panel2" Width="60%" Runat="server" BorderStyle="None" CssClass="pnlcriteria">
            <asp:TextBox id="txtLink" Width="700px" Runat="server" CssClass="Textentry"></asp:TextBox>
            <script for="Button2" event="onclick">
            function click()
     document.banners.txtLink.focus();    
     document.banners.txtLink.select();    
     var oControlRange = document.banners.txtLink.createTextRange();                    
     oControlRange.execCommand("copy");
   
            </script>
            
            <BR>
            <asp:HyperLink id="hypertest" Runat="server" Target="_blank"></asp:HyperLink>
            <BR>

            <asp:Button ID=Button2  Text=copy></asp:Button>
            
            <br>
      </asp:Panel>
      <BR>
</asp:panel>

and this sits within the aspx page code of

<body MS_POSITIONING="GridLayout">
            <form id="banners" method="post" runat="server">
                  <asp:PlaceHolder ID="phheader" Runat="server" />
            </form>
      </body>
0
suprapto45Commented:
Mmm...sorry but I cannot imagine that. Can you post the whole of your .aspx codes for me to look at?

I will be offline and hopefully can help you soon.

Regards
Dave
0
suprapto45Commented:
Oh thanks. I will look at the codes and tell you maybe in few hours time.

Regards
Dave
0
Robinsonx6Author Commented:
well the ascx code file above gets loaded into phheader which is a placeholder by

phheader.Controls.Add(LoadControl("banner.ascx"));


thats all the code

0
suprapto45Commented:
Hi,
I tried to check your codes. I found two problems there.

First, in the codes below, remove "function click()". It has no function.

          <script for="Button2" event="onclick">
          function click() // Remove It
     document.banners.txtLink.focus();    
     document.banners.txtLink.select();    
     var oControlRange = document.banners.txtLink.createTextRange();                    
     oControlRange.execCommand("copy");  
          </script>

Second, you missed the 'Runat="server"'

<asp:Button ID=Button2  Text=copy></asp:Button>
change it into
<asp:Button ID=Button2 Runat="server" Text=copy></asp:Button>

I cannot reply to you anymore until tommorow so I hope that helps.

Regards
Dave
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.