开发者

ViewState not persisted between callbacks, it IS enabled

开发者 https://www.devze.com 2023-02-13 18:09 出处:网络
Here is my code to add a viewsta开发者_如何学JAVAte key: if (ViewState[params[i].Name] != null || true){

Here is my code to add a viewsta开发者_如何学JAVAte key:

if (ViewState[params[i].Name] != null || true){
   if (ViewState[params[i].Name] == null) //create ViewState item
     ViewState[params[i].Name] = "SomeValue"; //...}

On the first Callback, the code runs and the ViewState item is added. However, on the second callback, when the first IF statement is hit to test for the ViewState item being there, it is not, it is NULL!!

ViewState is NOT DISABLED anywhere on my pages or controls. I thought the code above was the correct way to create a viewstate item to persist across multiple callbacks??

Thanks!


ViewState isn't handle for default on callbacks that why you got there null.

You can handle this for your own but it isn't easy that for sure.

Static field isn't a good aproach for any of that kind issues. It need to get unique key for every user in application if not it's will make hard to understand behaviour in the future.

Hope my answer make some light on this:)


Answering my own question.

I ended up creating a static dictionary for the info I needed. Does the job just fine.

0

精彩评论

暂无评论...
验证码 换一张
取 消