Solved

Retrieving clipboard data

Posted on 2007-11-15
3
405 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
This video teaches users how to migrate an existing Wordpress website to a new domain.
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.

743 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

15 Experts available now in Live!

Get 1:1 Help Now