Paste from clipboard in asp.net

  • Thread starter Thread starter Guest
  • Start date Start date
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!
 
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
 
Back
Top