Solved

Retrieving clipboard data

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

If I have to fix slow responding website my first thoughts are server side optimizations: the database may not be optimized or caching is not enabled, or things like that. We often overlook another major part of our web application: the client. We o…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Use Wufoo, an online form creation tool, to make powerful forms. Learn how to selectively show certain fields based on user input using rules to gather relevant information and data from your forms. The rules feature provides you with an opportunity…
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…

786 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