Click here to Skip to main content
14,298,693 members
Rate this:
Please Sign up or sign in to vote.
See more:

it is such that I have a textbox where I have some content in, and when I click the button clicks then it copies the content that is in textbox by itself, it should not be such that you have to run your mouse over to copy it. it just has to be like that when you click on the button that copies the it themselves.

i have try its here:

<asp:TextBox ID="TextBoxHenvis" CssClass="form-control input-lg" runat="server" ReadOnly="true"></asp:TextBox><br />
                <asp:Button ID="ButtonKopier" runat="server" Text="Kopier Link" OnClientClick="CopyToClipboard()" CssClass="btn btn-success" />

function CopyToClipboard() 
            var controlValue  = document.getElementById('<%=TextBoxHenvis.ClientID%>').value;

This means in other words that it should download content and so when you click ctrl + v then throw the content into which you got by click button.
Updated 11-May-15 11:15am
Rate this:
Please Sign up or sign in to vote.

Solution 1

Please see this article:[^].

See also:[^].

Note there is a pretty interesting trick described in the answer referenced above.

That said, browser make using clipboard pretty difficult, because automatic copy without the user consent it pretty dangerous; the user is unaware of that and can loose some data previously put to the clipboard. So, better don't do it at all.

Here is my advice: find any CodeProject code sample, say, your own code sample on this very page. Please click on "Copy Code". Are you getting the idea?
So, this is what I advise: use the CodeProject way: this is the simplest and at the same time the safest solution.

Rate this:
Please Sign up or sign in to vote.

Solution 2

Yes as Sergey says, you should tell the User that you are copying to clipboard while clicking the button or something.

Otherwise User would loose the existing clipboard data. So, change the button name like "copy to clipboard" or warn before copying.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100