Solved

Retrieving clipboard data

Posted on 2007-11-15
3
410 Views
Last Modified: 2012-10-22
Hello,
I am writing a c# asp.net application.
I have a div and 2 buttons - an html "Paste" button and an ASP "Submit" button.
When pressing the "Paste" button I am putting the text from the clipboard to the div using:
var text = clipboardData.getData("Text");
document.all("divData").innerHTML = text;

The problem is that when pressing the server side "Submit' button, I want to use the div's data. Instead of returning the data I just pasted from the clipboard, I get the data that was in the div previously.

I guess it is because the "Paste" function occurred on the client and the server doesn't know the data has changed.

How can I "Paste" data from the clipboard and use it in my "Submit" function?

Thank you
0
Comment
Question by:Relegence
3 Comments
 
LVL 14

Assisted Solution

by:cezarF
cezarF earned 100 total points
ID: 20287775
try this..

add a hidden textbox (style="visibility:hidden") and use a javascript function to store the div's innerHTML into it. call the javascript function upon clicking the submit button like btnSubmit.attributes.add("click", "jsfunction"). on the server-side click event of the submit button, read the hidden textbox's text.

0
 
LVL 3

Accepted Solution

by:
basharat_rehman earned 150 total points
ID: 20287807
you can use Hidden field
ASPX FILE:
----------------------------------------------------
<script language="javascript" type="text/javascript">
// <!CDATA[

function Button2_onclick() {
var text = clipboardData.getData("Text");
alert(text);

var mydiv = document.getElementById("ctl00_ContentPlaceHolder1_divData");
mydiv.innerHTML = text;

var myHidden = document.getElementById("ctl00$ContentPlaceHolder1$HiddenField1");
myHidden.value = text;

}

// ]]>
</script>

    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    <input id="Button2" type="button" value="button" onclick="return Button2_onclick()" />
    <div id ="divData" style="width: 100px; height: 100px" runat="server">
    </div>
    <asp:HiddenField ID="HiddenField1" runat="server" />
     <div id ="div2" style="width: 100px; height: 100px" runat="server">
    </div>


.CS File
--------------------------------------------------
protected void Button1_Click(object sender, EventArgs e)
        {
            div2.InnerHtml = divData.InnerHtml;
            div2.InnerHtml = HiddenField1.Value;

           
        }
-------------------------------------------------------
Note: I have placed a div where you are placing the clipboard data
 you can eliminate that if you just want to get that data at server


Basharat
0
 

Expert Comment

by:sebouhh
ID: 22345588
Hello
I've notice this was posted almost a year ago, but i tried the code, my divData.InnerHtml is bringing nothing. Also, the asp:hiddenfield is giving error, do you think this is .net version issue? i'm using 1.1

is there any other solution to read the innerHTML of div object?

thank you
Seb
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How can I build my own IDE using ASP.NET MVC? 2 34
Error in page 3 46
C#.NET and microsoft certification. 3 34
AWS ELB 5 17
New Relic: Our company recently started researching several products to figure out what were the best ways for us to increase our web page speed and to quickly identify performance problems that we may be having. One of the products we evaluated wa…
Introduction A frequently used term in Object-Oriented design is "SOLID" which is a mnemonic acronym that covers five principles of OO design.  These principles do not stand alone; there is interplay among them.  And they are not laws, merely princ…
This video teaches viewers how to create their own website using cPanel and Wordpress. Tutorial walks users through how to set up their own domain name from tools like Domain Registrar, Hosting Account, and Wordpress. More specifically, the order in…
Learn how to set-up custom confirmation messages to users who complete your Wufoo form. Include inputs from fields in your form, webpage redirects, and more with Wufoo’s confirmation options.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now