I use to append according to data array in table on button click, but wh开发者_高级运维en 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
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.
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.
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.
精彩评论