Solved

Retrieving clipboard data

Posted on 2007-11-15
3
417 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Foolproof security solutions has become one of the key necessities of every e-commerce or Internet banking website. If you too own an online shopping site then its vital for you to equip your web portal with customer security features that can allow…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to choose which pages of your form are visible to your users based on their inputs. The page rules feature provides you with an opportunity to create if:then statements for y…

632 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