Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can't post back the data that way in a div tag <em>if you are setting the value of the div on the client side</em>. You'll need to use a form element, like a hidden textbox if you want to use a straight ASP.NET postback.</p> <p>Here's a simple example. It uses a javascript event to set the text of a HiddenField when the button is pressed and then displays the text on postback.</p> <pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" %&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;script type="text/javascript"&gt; function copyToHiddenField() { var hidden = document.getElementById("&lt;%= txtHidden.ClientID %&gt;"); var theDivText = document.getElementById("thedata").innerHTML; hidden.value = theDivText; return true; } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form id="form1" runat="server"&gt; &lt;div id="thedata"&gt;Here's the data!&lt;/div&gt; &lt;asp:HiddenField ID="txtHidden" runat="server" /&gt; &lt;asp:Button ID="btnSumbit" Text="Submit" OnClick="btnSumbit_OnClick" runat="server" /&gt; &lt;asp:Literal ID="litText" runat="server" /&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; &lt;script runat="server"&gt; protected void Page_Load(object sender, EventArgs e) { btnSumbit.Attributes.Add("onclick", "return copyToHiddenField();"); } public void btnSumbit_OnClick(object sender, EventArgs e) { litText.Text = txtHidden.Value; } &lt;/script&gt; </code></pre> <p><strong>EDIT</strong><br /> As stated in the answers/comments, you can use the <code>InnerText</code> property of a <code>div</code> tag when <code>runat="server"</code> is specified, but you will only be able read out the <code>InnerText</code> that is set when the page is rendered. Client side updates to the <code>InnerText</code> of the div will not be sent to the server on postback.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload