How to personalise a javascript according to my asp.net application?

Last post 12-17-2007 10:27 PM by Thomas Sun – MSFT. 2 replies.

Sort Posts:

  • How to personalise a javascript according to my asp.net application?

    12-14-2007, 4:27 AM
    • Loading...
    • bonfa
    • Joined on 08-31-2007, 4:05 PM
    • Posts 72

    Hi i have an asp.net application, i am using also visual basic with visual web developer 2005 express. I have a formview with one button and one textbox, i want to be able to click the button and copy the content of the textbox like Ctrl C to paste this data in other application. How can i modify the java script to work on my code?

    here is my code: 

     <asp:FormView ID="FormView1" runat="server" CellPadding="4" DataSourceID="SqlDataSource1"
            ForeColor="#333333" GridLines="Both" HeaderText="Copy">
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <EditRowStyle BackColor="#999999" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <ItemTemplate>
                <table style="width: 495px; height: 84px" border="1" bordercolor="gainsboro">
                    <tr>
                        <td style="width: 156px; text-align: left;">
                            <asp:Label ID="Label3" runat="server" Font-Bold="True" Font-Names="Arial" Font-Size="Small"
                                Text="Order ID:"></asp:Label></td>
                        <td style="width: 302px">
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("order_number", "{0}") %>'
                                Width="250px"></asp:TextBox>
                            <asp:Button ID="Button1" runat="server" Text="Button" /></td>
                    </tr>

     

    that's the javascript i've found:

     

    <script>

    function ClipBoard(tdObj)

    {

    var holdtext = document.all['holdtext'];

    holdtext.innerText = tdObj.innerText;

    Copied = holdtext.createTextRange();

    Copied.execCommand("Copy");

    }

    </script>
    .
    .
    .
    <td><img src=“copy.gif“ onclick=“ClipBoard(this.parentElement)“> TEXT TO COPY</td>
    .
    .
    <textarea id=“holdtext“ style=“display:none“></textarea>

     

  • Re: How to personalise a javascript according to my asp.net application?

    12-14-2007, 11:10 AM
    Answer
    • Loading...
    • onSlaught
    • Joined on 08-21-2007, 5:17 PM
    • a Phoenician
    • Posts 373

    This should get you the textbox text and place it into Copied variable:
    Copied = document.getElementById("textbox1").value


    Please mark as "answer" if this helped you in anyway.
  • Re: How to personalise a javascript according to my asp.net application?

    12-17-2007, 10:27 PM
    Answer

    Hi Bonfa,

    Based on my understanding, you want to copy the TextBox’s value and paste this value in another place just like Ctrol+C. But this TextBox is within the FromView.  If I have misunderstood you, please feel free to let me know.

    I agree with the member above. We just need to refer to this TextBox in the JavaScript. But this TextBox is in the FormView, we can refer to this TextBox by the client id (such as FormView1$TextBox1, if the TextBox's id is TextBox1).

    For example:

    <%@ Page Language="C#" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
    
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Untitled Page</title>
    
        <script type="text/javascript">
    
    function ClipBoard() 
    {
    
    var holdtext = document.all['holdtext'];
    
    holdtext.innerText =document.getElementById("FormView1$TextBox1").value
    
    Copied = holdtext.createTextRange();
    Copied.execCommand("Copy");
    
    }
    
        </script>
    
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
    <textarea id="holdtext" style="display:none"></textarea>
    
            <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1">
                <ItemTemplate>
                    <asp:TextBox ID="TextBox1" runat="server" Text="Test"></asp:TextBox><br />
                    <asp:Button ID="Button1" runat="server" Text="CopyText" OnClientClick="ClipBoard()" />
                </ItemTemplate>
            </asp:FormView>
            
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:aspnetforumConnectionString %>"
                SelectCommand="SELECT * FROM [dateTable]"></asp:SqlDataSource>
        </div>
        </form>
    </body>
    </html>
     

     

    I hope this helps. 

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
Page 1 of 1 (3 items)
Microsoft Communities
Page view counter