How to Copy the Text of a textbox to Clipboard? - ASP TANMOY

Latest

Monday 12 March 2018

How to Copy the Text of a textbox to Clipboard?

In my previous post I have explained How to create XML SiteMap Dynamically in ASP.Net. Today I will explain How to Copy the Text of a textbox to Clipboard?. It is very simple. You can do it using JavaScript or Jquery.

Step 1: Add below code to your design page.

  1. <p id="p1" style="display:none"></p>

  2.                 <asp:TextBox ID="txtReferalLink" runat="server" CssClass="form-control"></asp:TextBox><span><a onclick="copyToClipboard('#p1')" href="javascript:void(0);" class="btn btn-info">Copy Url</a></span>


Step 2: Add the below code inside the page header.
  1. <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  2.     <script>
  3.         function copyToClipboard(element) {

  4.             var controlValue = document.getElementById('<%=txtReferalLink.ClientID%>').value;
  5.             document.getElementById('p1').innerHTML = controlValue;

  6.             var $temp = $("<input>");
  7.             $("body").append($temp);
  8.             $temp.val($(element).text()).select();
  9.             document.execCommand("copy");
  10.             $temp.remove();
  11.             alert('Url has copied');
  12.         }

  13.     </script>



2 comments:

  1. How To Copy The Text Of A Textbox To Clipboard? - Asp Tanmoy >>>>> Download Now

    >>>>> Download Full

    How To Copy The Text Of A Textbox To Clipboard? - Asp Tanmoy >>>>> Download LINK

    >>>>> Download Now

    How To Copy The Text Of A Textbox To Clipboard? - Asp Tanmoy >>>>> Download Full

    >>>>> Download LINK

    ReplyDelete