[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2004-11-19
23
Medium Priority
?
212 Views
Last Modified: 2010-03-31
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?
0
Comment
Question by:Robinsonx6
  • 10
  • 9
  • 2
  • +1
23 Comments
 
LVL 13

Expert Comment

by:petmagdy
ID: 12624322
Robinsonx6

Are u sure u submitted to the right place? this is the java topic channel
0
 
LVL 2

Author Comment

by:Robinsonx6
ID: 12624334
yeah i assumed because it would need to be done client side i would need to use javascript
0
 
LVL 13

Expert Comment

by:petmagdy
ID: 12624348
no here too, their is other topic for javascript
0
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!

 
LVL 2

Author Comment

by:Robinsonx6
ID: 12624356
ok ill get this one closed by the page editor

thanks
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 12624674
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
 
LVL 16

Expert Comment

by:suprapto45
ID: 12625033
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
 
LVL 2

Author Comment

by:Robinsonx6
ID: 12625083
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
 
LVL 2

Author Comment

by:Robinsonx6
ID: 12625147
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
 
LVL 37

Expert Comment

by:zzynx
ID: 12625398
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
 
LVL 2

Author Comment

by:Robinsonx6
ID: 12625457
tried it still didnt work! im still getting document.banners.txtLink does not exist or is null?
any more ideas
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12625509
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
 
LVL 16

Expert Comment

by:suprapto45
ID: 12625528
Hi,

Can you post the whole of your .aspx file?

Best Regards
Dave
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 12625543
Oh yes,

Please change your button to the .aspx format and not the simple as <button id=Button2>Copy text 2</button>
0
 
LVL 2

Author Comment

by:Robinsonx6
ID: 12625713
zzynx the answer is no to your comment :-)
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 12625747
Dear Robinsonx6,

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

Regards
Dave
0
 
LVL 2

Author Comment

by:Robinsonx6
ID: 12625758
no i didnt once you use an asp:button the code doesnt get run
0
 
LVL 16

Expert Comment

by:suprapto45
ID: 12625782
Can you post your .aspx for me to look at?
Are these codes within <form>...</form>

Regards
Dave
0
 
LVL 2

Author Comment

by:Robinsonx6
ID: 12625800
the code is within an ascx control file loaded within the form element of the parent aspx page
0
 
LVL 2

Author Comment

by:Robinsonx6
ID: 12625819
<%@ 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
 
LVL 16

Expert Comment

by:suprapto45
ID: 12625834
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
 
LVL 16

Expert Comment

by:suprapto45
ID: 12625870
Oh thanks. I will look at the codes and tell you maybe in few hours time.

Regards
Dave
0
 
LVL 2

Author Comment

by:Robinsonx6
ID: 12625881
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
 
LVL 16

Accepted Solution

by:
suprapto45 earned 1500 total points
ID: 12626135
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

Featured Post

Technology Partners: 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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses
Course of the Month19 days, 11 hours left to enroll

872 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