how to implement copy function in asp.net

  • Thread starter Thread starter TaeHo Yoo
  • Start date Start date
T

TaeHo Yoo

I am trying to copy a string in a text box into clipboard and what I did
was

Imports System.Windows.Forms

and


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Clipboard.SetDataObject(TextBox1.Text, True)
End Sub


but this generates an error saying

-----------------------------------------------------
The current thread must set to Single Thread Apartment (STA) mode before
OLE calls can be made. Ensure that your Main function has
STAThreadAttribute marked on it.
-----------------------------------------------------

Any idear what this means?
Could you help me?

Thanks in advance.
 
Hi,

you should start a new thread and make it use STA. Inside the thread you
will be able to call the Clipboard function. The problem is that certain
Windows COM objects require STA and ASP.NET by default is MTA. You also
could set the ASPCompat Mode to true which means that ASP.NET will work in
STA mode. But I would recommend it.

Best regards,

Marc Höppner
NeoGeo
 
Thanks for your advice.
Which way would you recommend? and how to set ASPCompat Mode to true?
If I set ASPCompat Mode to true is there any risks involved?
 
I would recommend using a different thread which is set to STA. Setting the
whole ASPX process to STA has some other drawbacks, one example being
greatly reduced performance. If that is not a problem in your scenario, you
can lookup the <page...> element in MSDN, there is an attribute called
something like aspcompat that you can set on the Page

Best regards,

Marc Höppner
NeoGeo
 
Back
Top