Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Retrieving clipboard data

Posted on 2007-11-15
3
Medium Priority
?
418 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 400 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 600 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Developer tools in browsers have been around for a while, yet they are still heavily underused by developers. Developers still fix html or CSS then refresh page to see effect, or they put alert or debugger in JavaScript and then try again and again …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Wufoo.com provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.
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…

721 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