Paste from clipboard in asp.net

Discussion in 'ASP .Net' started by =?Utf-8?B?ZnM=?=, Feb 20, 2005.

  1. 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!
    =?Utf-8?B?ZnM=?=, Feb 20, 2005
    #1
    1. Advertising

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

    "fs" <> wrote in message
    news:...
    > 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], Feb 21, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    747
  2. tabonni
    Replies:
    1
    Views:
    173
    Jeff Cochran
    Sep 5, 2004
  3. Dan Bishop
    Replies:
    0
    Views:
    214
    Dan Bishop
    Aug 26, 2008
  4. Replies:
    4
    Views:
    253
    Randy Webb
    Dec 14, 2004
  5. Mahsha

    Clipboard - Copy Image To Clipboard

    Mahsha, Jun 1, 2009, in forum: Javascript
    Replies:
    1
    Views:
    560
    Thomas 'PointedEars' Lahn
    Jun 1, 2009
Loading...

Share This Page