Wednesday, 8 January 2014

jQuery:Copy and Paste User Selected Text in ASP.NET

Hi friends,in this article I will explain about jQuery:Copy and Paste User Selected Text in ASP.NET.

Write the below code in the .aspx page

ASP.NET:                                       Previous Article>>Select Multiple records in GridView with Ctrl Key
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>jQuery:Copy and Paste User Selected Text in ASP.NET </title>
    <script src="//code.jquery.com/jquery-1.10.2.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            var copied = '';
            $("#btnPaste").click(function () {
                $("#txtCopied").text(copied);
            });
            $("#btnCopy").click(function () {
                copied = selectedText.Selector.getSelected();
            });
        });

        if (!window.selectedText) {
            selectedText = {};
        }
        selectedText.Selector = {};

        selectedText.Selector.getSelected = function () {
            var t = '';
            if (window.getSelection) {
                t = window.getSelection();
            } else if (document.selection) {
                t = document.selection.createRange().text;
            } else if (document.getSelection) {
                t = document.getSelection();
            }
            return t;
        }     
                                                         
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <h4 style="color: Green">
        Select some text on the page ...</h4>
    <p>
        ASP.NET,VB.NET,C#.NET,SQL Server,JavaScript,JQuery</p>
    <p>
        Angular JS,MVC,Web Services,WCF,WPF,AJAX,XML,HTML</p>
    <p>
        ASP.NET,VB.NET,C#.NET,SQL Server,JavaScript,JQuery</p>
    <p>
        Angular JS,MVC,Web Services,WCF,WPF,AJAX,XML,HTML</p>
    <input type="button" id="btnCopy" name="btnCopy" value="Copy" />
    <input type="button" id="btnPaste" name="btnPaste" value="Paste" /><br />
    <asp:TextBox ID="txtCopied" runat="server" TextMode="MultiLine" Width="150px" Height="100px"></asp:TextBox>
    </form>
</body>
</html>


The output of the above code as shown in the below figure.

You can download the code by clicking on the below Download image. 
"If you like my blog or articles, you can appreciate by leaving your comments or Liking my Facebook pageAspdotnet-kishore, following on Google+ Aspdotnet-Kishore, Twitter  on AspdotnetKishore, Linked in Aspdotnet-Kishore, stumbling my posts on stumble upon and subscribing on  RSSfeed Aspdotnet-Kishore for free updates directly to your Email inbox . Watch my blog  for more articles."

No comments:

Post a Comment

© 2012-2018 Aspdotnet-Kishore.blogspot.com. All Rights Reserved.
The content is copyrighted to Kishore and may not be reproduced on other websites without permission from the owner.