0

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

1
  • So you are only updating the span innerHTML on the client? Don't you think you need to store the change on the server or get a new set of data to show? You could use the $.ajax function to update the value without refreshing the page. Commented Aug 2, 2011 at 8:26

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Ok Thanks Guffa ,if it my only option I will use your advice
@baaroz: It's not the only option, but one of the simplest. Another option would for example to create a cookie in the browser to send the value along to the server.
yes but all this options isn't ideal,it a little bit clumsy .I tought there is something like "reqeust.form" ,thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.