Copy Code Link

Discussion in 'ASP .Net Web Controls' started by Morris Neuman, Sep 20, 2009.

  1. Hi,

    What control do I use to simulate the Copy Code feature provided in many
    walkthroughs? In all walkthroughs, sample code is proved in a gray box which
    has a link copy code. When the user presses this link, the sample code in
    the grey box is downloaded and saved to your clipboard.

    Any links/walkthroughs on how to do this?
     
    Morris Neuman, Sep 20, 2009
    #1
    1. Advertisements

  2. Hi Morris,

    You can try the following code to achieve this. However, this method only
    works in IE. As far as I know, there is no elegant solution for FireFox.

    <div>
    <script type="text/javascript">
    function Copy() {
    var data = document.getElementById('<%=Panel1.ClientID
    %>').innerHTML;
    window.clipboardData.setData('Text', data);
    alert("done!");
    }
    </script>
    <a href="javascript:Copy()">Copy to ClipBoard</a>
    <asp:panel BackColor="Gray" ID="Panel1" runat="server">
    Hello World
    </asp:panel>
    </div>

    Please let me know if it works and feel free to ask if you have additional
    questions.

    Regards,
    Allen Chen
    Microsoft Online Support

    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .

    ==================================================
    Get notification to my posts through email? Please refer to
    http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

    Note: MSDN Managed Newsgroup support offering is for non-urgent issues
    where an initial response from the community or a Microsoft Support
    Engineer within 2 business day is acceptable. Please note that each follow
    up response may take approximately 2 business days as the support
    professional working with you may need further investigation to reach the
    most efficient resolution. The offering is not appropriate for situations
    that require urgent, real-time or phone-based interactions. Issues of this
    nature are best handled working with a dedicated Microsoft Support Engineer
    by contacting Microsoft Customer Support Services (CSS) at
    http://msdn.microsoft.com/en-us/subscriptions/aa948874.aspx
    ==================================================
    This posting is provided "AS IS" with no warranties, and confers no rights.
     
    Allen Chen [MSFT], Sep 21, 2009
    #2
    1. Advertisements

  3. Hi Allen,

    That worked. However I am creating page using html only so cannot use panel
    or as asp code. The page has several tables and I want to copy code from a
    row in the table.

    The Page below has 2 tables, each table has 2 rows. I want a link on row 1
    "Copy code below" that when used would copy to clipboard. How can I do
    that?

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
    <HTML>
    <HEAD>
    <META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">
    <TITLE>Walkthrough: Test Code Copy</TITLE>
    <link href="../html/style.css" rel="stylesheet" type="text/css" >

    </HEAD>

    <BODY>

    <h3>Walkthrough: Test Code Copy</h3>

    <p>Let's create the scripts first. Open Notepad and create scripts
    following
    code examples below. Remember to save them as .bas type files in the
    Program Files\CALLMaster\Scripts folder.</p>
    <table class="script" border="1" cellspacing="0" style="width: 844px">
    <tr>
    <td><strong>CALLBasic Script - Entry.bas </strong></td>
    <td><strong>Cope code below</strong></td>
    </tr>
    <tr>
    <td colspan="2">Program<br> Print "CM Entry Script started
    on "<br> PrintNL $today<br><br>
    ' @SponsorNo set to 0<br> @SponsorNo = 0<br><br>
    EndProgram<br><br></td>
    </tr>
    </table>
    <table class="script" border="1" cellspacing="0" style="width: 844px">
    <tr>
    <td><strong>CALLBasic Script - Check-n-Set-SponsorNo.bas</strong></td>
    <td><strong>Cope code below</strong></td>
    </tr>
    <tr>
    <td colspan="2">Program<br> ' This script uses the Return
    command with a variable. When used with an Audiotex module whose
    action is Audiotex, the caller will be forwarded to the Audiotex module
    whose
    number is equal to variable strRetVar.<br> Return strRetVar<br>
    <br>EndProgram<br><br></td>
    </tr>
    </table>

    </BODY>
    </HTML>
     
    Morris Neuman, Sep 21, 2009
    #3
  4. Hi Allen,

    Tried naming the table row and referring to the name in the java script but
    get error.

    I have emailed you with page attached.
     
    Morris Neuman, Sep 21, 2009
    #4
  5. Hi Morris,

    Thanks for your reply. Please try this:


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
    <HTML>
    <HEAD>
    <META HTTP-EQUIV="Content-Type" Content="text/html; charset=Windows-1252">
    <TITLE>Walkthrough: Test Code Copy</TITLE>
    <link href="../html/style.css" rel="stylesheet" type="text/css" >

    </HEAD>

    <script type="text/javascript">
    function Copy() {
    //var data = document.getElementById('<%=Panel1.ClientID
    %>').innerHTML;
    var data = document.getElementById('entryscript').innerText;
    window.clipboardData.setData('Text', data);
    alert("done!");
    }
    </script>

    <BODY>


    <h3>Walkthrough: Test Code Copy</h3>

    <p>Let's create the scripts first.&nbsp; Open Notepad and create scripts
    following
    code examples below.&nbsp; Remember to save them as .bas type files in the
    Program Files\CALLMaster\Scripts folder.</p>
    <table id="tableEntry" class="script" border="1" cellspacing="0"
    style="width: 844px">
    <tr>
    <td><strong>CALLBasic Script - Entry.bas </strong></td>
    <td><a href="javascript:Copy()">Copy to Clip Board</a></td>
    </tr>
    <tr>
    <td id="entryscript" colspan="2">Program<br>&nbsp;&nbsp;&nbsp;&nbsp;
    Print &quot;CM Entry Script started
    on &quot;<br>&nbsp;&nbsp;&nbsp;&nbsp; PrintNL
    $today<br><br>&nbsp;&nbsp;&nbsp;&nbsp;
    ' @SponsorNo set to 0<br>&nbsp;&nbsp;&nbsp;&nbsp; @SponsorNo = 0<br><br>
    EndProgram<br><br></td>
    </tr>
    </table>


    <table class="script" border="1" cellspacing="0" style="width: 844px">
    <tr>
    <td><strong>CALLBasic Script - Check-n-Set-SponsorNo.bas</strong></td>
    <td><strong>Cope code below</strong></td>
    </tr>
    <tr>
    <td colspan="2">Program<br>&nbsp;&nbsp;&nbsp;&nbsp; ' This script uses
    the Return
    command with a variable.&nbsp; When used with an Audiotex module whose
    action is Audiotex, the caller will be forwarded to the Audiotex module
    whose
    number is equal to variable strRetVar.<br>&nbsp;&nbsp;&nbsp;&nbsp; Return
    strRetVar<br>
    <br>EndProgram<br><br></td>
    </tr>
    </table>

    </BODY>
    </HTML>


    Regards,
    Allen Chen
    Microsoft Online Support

    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .
     
    Allen Chen [MSFT], Sep 22, 2009
    #5
  6. Thanks. That worked.

    Can you email link where I can get more info on the java script commands and
    parameters?
     
    Morris Neuman, Sep 22, 2009
    #6
  7. Hi Morris,
    Thanks for your update. You can refer to MSDN for more information:

    http://msdn.microsoft.com/en-us/library/ms533050(VS.85).aspx

    If you have additional questions please feel free to ask.

    Regards,
    Allen Chen
    Microsoft Online Support

    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .
     
    Allen Chen [MSFT], Sep 23, 2009
    #7
  8. Hi Morris,
    Do you have additional questions?

    Regards,
    Allen Chen
    Microsoft Online Support

    Delighting our customers is our #1 priority. We welcome your comments and
    suggestions about how we can improve the support we provide to you. Please
    feel free to let my manager know what you think of the level of service
    provided. You can send feedback directly to my manager at:
    .
     
    Allen Chen [MSFT], Sep 25, 2009
    #8
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Similar Threads
There are no similar threads yet.
Loading...