Click here to Skip to main content
15,891,431 members

Copy to Clipboard in ASP.NET-C#

Janani Muthaiyan asked:

Open original thread
Copying the label text using LinkButton to clipboard says "Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it."
Here is my asp tag..
ASP.NET
<asp:Label ID="label" runat="server" Text="text to be copied"></asp:Label>
<asp:LinkButton ID="LinkButton1" runat="server"  OnClick="LinkButton1_Click">LinkButton</asp:LinkButton>

Code-behind: C#
C#
protected void LinkButton1_Click(object sender, EventArgs e)
        { 
            Clipboard.SetText(label.Text);
        }

While click this LinkButton it shows error as I said above.. I could not use javascript / jquery in my application.. It is purely the server side web application. Please do post possible solution in c# itself.. If you all suggest me javascript clipboard, please provide me the solution that works out in all browser.
Tags: C#, ASP.NET, Clipboard

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900