Paste from clipboard in asp.net

G

Guest

Hi all,

I have a page that i need to implement a button that says "Paste to
textbox1", which will paste the text content in clipboard to a textbox
control on postback. How can I get values from the windows clipboard in
asp.net?

Please help, thanks in advance!
 
K

Ken Cox [Microsoft MVP]

This is something you can only do on the client-side using JavaScript.
However, you can emit the required code from ASP.NET.

Here's an example of how you might accomplish it. This will only function in
Internet Explorer.

Private Sub Page_Load(ByVal sender As _
System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
btnPaste.Attributes.Add("onclick", _
"PasteIt();return false;")
' btnPaste.Attributes.Add("name", "btnPaste")
Page.RegisterClientScriptBlock("pastroutine", _
"<script>function PasteIt()" & _
"{document.all.TextBox2.focus();" & _
"document.execCommand('paste');}</script>")
End Sub

<asp:button id="btnPaste" runat="server" Text="Paste from
Clipboard"></asp:button></p>
<p>
<asp:textbox id="TextBox2" runat="server"></asp:textbox></p>

More on the use of execCommand here:

http://msdn.microsoft.com/workshop/author/dhtml/reference/methods/execcommand.asp?frame=true

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
Toronto
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top