Reputation: 19587
I have this HTML tag:
<span id="pricea" runat="server">13323223</span>
and I am changing this value with JavaScript:
<script type="text/javascript">
$(function () {
$("#pricea").hover(function () {
document.getElementById("pricea").innerHTML = "1234"
});
});
</script>
Now,when I do postback after clicking asp:Button
, the span value returns to be the original value and I can't take the new value that was changed by the JavaScript.
I thought maybe use request.form("pricea"), but it seem to be working only for input fields, so my question is:
how can I get the value of this span (after it was change by the JavaScript) in server side?
thanks for any help
Upvotes: 0
Views: 1940
Reputation: 700232
The HTML document is not posted back to the server, only the content in the fields in the form.
If you want to send the value back to the server, you have to put it in a form field. You can add a hidden field to the form where you can keep a copy of the content of the span:
<asp:Hidden name="pricea_copy" id="pricea_copy" />
Now when you change the span
, you also change the hidden field:
document.getElementById("pricea").innerHTML = "1234";
document.getElementById("pricea_copy").value = "1234";
After the postback, you can access the changed value in the hidden field using pricea_copy.Value
, and use that to set the content of the span tag for the new page.
Upvotes: 2