A common question I come across is "Can I pass viewstate between pages for getting information?" and the answer on all web pages I found is NO.
BUT,
Say I have Page1 having a button. On click of button I can get the value of __viewstate hidden field, append it in querystring and pass it on to another page. There I can decode it and use the information. OR ELSE I can also do a postback to another page, get the Viewstate data using request.form("__Viewstate"), decode it and again use the information. Then why do people say viewstate can not be transfered between pages???
>Then why do people say viewstate can not be transfered between pages?
The viewstate is not being transferred - a copy of it is being transferred (or at least an attempt is being made to transfer a copy).
When people ask this question, I think they are looking for a built-in, automatic way, i.e. NewPage.ViewState = OldPage.ViewState. And the proper answer to that is No, there's no pre-built method for doing that.
But of course any problem can be solved with hard work and ingenuity, as your two examples show. But both your examples require you to write your own code to copy the old viewstate to the new one. The question implies the poster is looking for an existing method that does the copying for them, and the answer would be no.
0 comments:
Post a Comment