how to implement copy function in asp.net

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.
 
M

Marc Hoeppner

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
 
T

TaeHo Yoo

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?
 
M

Marc Hoeppner

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top