Connecting Tech Pros Worldwide Help | Site Map

Paste from clipboard in asp.net

fs
Guest
 
Posts: n/a
#1: Nov 19 '05
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!
Ken Cox [Microsoft MVP]
Guest
 
Posts: n/a
#2: Nov 19 '05

re: Paste from clipboard in asp.net


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/a...asp?frame=true

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
Toronto

"fs" <fs@discussions.microsoft.com> wrote in message
news:E2D0FC3E-9EF6-495C-AE4A-ADCF47C390EF@microsoft.com...[color=blue]
> 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![/color]

Closed Thread