Copy text to clipboard

Answered
0
0

I understand that copying to the client clipboard has to be done in 2 operations… Clipboard.SetClientText writes to temporary storage on the client.  And then javascript can execute Wisej.Core.Copy(); to retrieve that text and put it on the clipboard.

But its not working for me.  Here is my code.  What am I doing wrong?

Thanks in advance,

Matthew

 

Private Sub lblURL_Click(sender As Object, e As EventArgs) Handles lblURL.Click
Wisej.Web.Clipboard.SetClientText(lblURL.Text)
Me.Eval("Wisej.Core.copy();")
End Sub

  • You must to post comments
Best Answer
0
0

Thank you Luca, I see the distinction now.

I implemented it using a button (called “Copy”) which sets the text on the client side, and displays a confirming button (called “Copy URL?”).  The confirming button uses the javascript extender control and executes the javascript to do the copy().

Works perfectly, thanks.

 

 

  • You must to post comments
1
0

Found a better solution. You can do both steps with 1 click and 1 button. Attach the “execute” event using the Javascript extender and use this js code:

setTimeout(function(){
    
    Wisej.Core.copy();
    
    var box = new wisej.web.AlertBox().set({
        icon:"information",
        message:"Clipboard data copied!"
    });
    box.show();
    
}, 500);

 

Adjust as needed. Then attach the click event handler on the server (same button) and use SetClientText(). Turns out that the click will execute both, the client code and the server code and setTimeout() marks the function as “safe” when started from a user event. You  may have to adjust the 500ms timeout or check if Wisej.Core.clipoardText is > “” or reschedule.

 

  • You must to post comments
0
0

You can’t call “copy()” from the server, that’s why we need two steps. All browsers stop ajax calls from setting the clipboard. copy() must be called on the client by a client-initiated event, like a user click and a javascript client side only event.

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.