Copy To Clipboard Problem

W

Wayne Wengert

I have an aspx page on which I am trying to copy the contents of a textbox
to the client clipboard when the users clicks a button. The button code is
as follows:
=====================================
Private Sub btnCopyToClipboard_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnCopyToClipboard.Click

Clipboard.SetDataObject(txtHidden.Text)

End Sub

=================================================

When the button is clicked, I am getting the following error pointing to the
statement in the above sub.

==================================================

Exception Details: System.Threading.ThreadStateException: 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.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:

[ThreadStateException: 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.]
System.Windows.Forms.Clipboard.SetDataObject(Object data, Boolean copy)
+512
System.Windows.Forms.Clipboard.SetDataObject(Object data) +7
WBA_StaffControls.frmJudgeCommunications.btnCopyToClipboard_Click(Object
sender, EventArgs e) in
c:\inetpub\wwwroot\WBA_StaffControls\frmJudgeCommunications.aspx.vb:312
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1292


=========================================================



Any thought on how to correct this problem?



Wayne
 
W

Wayne Wengert

Thanks for the quick response. Do you have a pointer to any exanples of how
to do this?

Wayne

Eliyahu Goldin said:
Wayne,

Client clipboard is located on the client machine. Your code tries to set
your web server's clipboard. On client side you can use javascript
window.clipboardData object.

Eliyahu

Wayne Wengert said:
I have an aspx page on which I am trying to copy the contents of a
textbox
to the client clipboard when the users clicks a button. The button code
is
as follows:
=====================================
Private Sub btnCopyToClipboard_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles btnCopyToClipboard.Click

Clipboard.SetDataObject(txtHidden.Text)

End Sub

=================================================

When the button is clicked, I am getting the following error pointing to the
statement in the above sub.

==================================================

Exception Details: System.Threading.ThreadStateException: 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.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:

[ThreadStateException: 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.]
System.Windows.Forms.Clipboard.SetDataObject(Object data, Boolean
copy)
+512
System.Windows.Forms.Clipboard.SetDataObject(Object data) +7
WBA_StaffControls.frmJudgeCommunications.btnCopyToClipboard_Click(Object
sender, EventArgs e) in
c:\inetpub\wwwroot\WBA_StaffControls\frmJudgeCommunications.aspx.vb:312
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
stBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+33
System.Web.UI.Page.ProcessRequestMain() +1292


=========================================================



Any thought on how to correct this problem?



Wayne
 
W

Wayne Wengert

Thank you. I'll use that link and see if I can get this working.

Wayne

Eliyahu Goldin said:
If you have MSDN library installed, just find "clipboardData" in the
index.
Alternatively go to
http://msdn.microsoft.com/library/d...hor/dhtml/reference/objects/clipboardData.asp

You will find an example there.

Eliyahu

Wayne Wengert said:
Thanks for the quick response. Do you have a pointer to any exanples of how
to do this?

Wayne

Eliyahu Goldin said:
Wayne,

Client clipboard is located on the client machine. Your code tries to set
your web server's clipboard. On client side you can use javascript
window.clipboardData object.

Eliyahu

I have an aspx page on which I am trying to copy the contents of a
textbox
to the client clipboard when the users clicks a button. The button
code
is
as follows:
=====================================
Private Sub btnCopyToClipboard_Click(ByVal sender As System.Object, ByVal
e
As System.EventArgs) Handles btnCopyToClipboard.Click

Clipboard.SetDataObject(txtHidden.Text)

End Sub

=================================================

When the button is clicked, I am getting the following error pointing to
the
statement in the above sub.

==================================================

Exception Details: System.Threading.ThreadStateException: 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.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:

[ThreadStateException: 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.]
System.Windows.Forms.Clipboard.SetDataObject(Object data, Boolean
copy)
+512
System.Windows.Forms.Clipboard.SetDataObject(Object data) +7

WBA_StaffControls.frmJudgeCommunications.btnCopyToClipboard_Click(Object
sender, EventArgs e) in
c:\inetpub\wwwroot\WBA_StaffControls\frmJudgeCommunications.aspx.vb:312
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108

System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
stBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+33
System.Web.UI.Page.ProcessRequestMain() +1292


=========================================================



Any thought on how to correct this problem?



Wayne
 
E

Eliyahu Goldin

Wayne,

Client clipboard is located on the client machine. Your code tries to set
your web server's clipboard. On client side you can use javascript
window.clipboardData object.

Eliyahu
 
E

Eliyahu Goldin

If you have MSDN library installed, just find "clipboardData" in the index.
Alternatively go to
http://msdn.microsoft.com/library/d...hor/dhtml/reference/objects/clipboardData.asp

You will find an example there.

Eliyahu

Wayne Wengert said:
Thanks for the quick response. Do you have a pointer to any exanples of how
to do this?

Wayne

Eliyahu Goldin said:
Wayne,

Client clipboard is located on the client machine. Your code tries to set
your web server's clipboard. On client side you can use javascript
window.clipboardData object.

Eliyahu

Wayne Wengert said:
I have an aspx page on which I am trying to copy the contents of a
textbox
to the client clipboard when the users clicks a button. The button code
is
as follows:
=====================================
Private Sub btnCopyToClipboard_Click(ByVal sender As System.Object,
ByVal
e
As System.EventArgs) Handles btnCopyToClipboard.Click

Clipboard.SetDataObject(txtHidden.Text)

End Sub

=================================================

When the button is clicked, I am getting the following error pointing
to
the
statement in the above sub.

==================================================

Exception Details: System.Threading.ThreadStateException: 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.

Source Error:

An unhandled exception was generated during the execution of the
current web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.

Stack Trace:

[ThreadStateException: 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.]
System.Windows.Forms.Clipboard.SetDataObject(Object data, Boolean
copy)
+512
System.Windows.Forms.Clipboard.SetDataObject(Object data) +7
WBA_StaffControls.frmJudgeCommunications.btnCopyToClipboard_Click(Object
sender, EventArgs e) in
c:\inetpub\wwwroot\WBA_StaffControls\frmJudgeCommunications.aspx.vb:312
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePo
stBackEvent(String
eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
+33
System.Web.UI.Page.ProcessRequestMain() +1292


=========================================================



Any thought on how to correct this problem?



Wayne
 

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

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,229
Latest member
GloryAngul

Latest Threads

Top