Best way to save variables between postbacks asp.net?

后端 未结 2 1735
庸人自扰
庸人自扰 2021-01-04 13:03

How can I save variables in asp.net between postback? I\'m using HttpContext.Current.Items but it always disposes after postback is there any other option to do that?

2条回答
  •  太阳男子
    2021-01-04 13:43

    If your variable is not serializable or you do not want the client to be able to read its value => use inProc Session

    If your variable is serializable and you do not want the client to be able to read its value => use database Session

    if your variable is serializable, and you can live with the client reading its value, and it should only live during the postbacks sequence in the scope of the page => you should use ViewState.

提交回复
热议问题