3

I use to append according to data array in table on button click, but when I click other button due to postback all the created structure goes away, is there any way that I can retain that structure inspite of postback?

Thanx

1
  • 1
    I'd suggest you change your question title to Retain Javascript objects across postbacks in order to attract more pertinent answers, because static fields are an entirely different concept (and are indeed supported by Javascript). Commented Feb 12, 2011 at 12:26

3 Answers 3

4

When you redirect to another page all values that were stored in javascript variables are garbage collected and are no longer available. There are different techniques allowing you to persist values on the client side. One is using cookies. Another is using HTML5 local storage.

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

Comments

1

No. Making a post request leaves the current page, and the current page is the execution environment.

You'll need to include all the data you need to reconstruct the state in the submitted data and then rebuild it on the other side.

Comments

1

If you need to preserve Javascript state across postbacks then your best bet is to serialise your data and store it in a hidden form field whenever it changes, then reload from this field at page reload time. However, I'd recommend if possible replacing the postbacks with AJAX calls to prevent them happening in the first place.

Comments

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.