Database request in Page_Load
In Page_Load
I create dynamic controls (table with checkboxes). N开发者_如何转开发umber of checkboxes depends on some information that I retrieve from my database. I don't want to connect to the database on every postback. What is the best way to save needed variables? Maybe I need to store them in HiddenField
?
store them inside the viewstate, which is more or less storing in a hiddenField (as the viewstate itself gets persisted to a hiddenfield)
viewstate @ msdn
It is recommended to get your variables values from database in this case. However, if you choose not to follow the recommendation, you still can store these values as session state variables if it is ok in your system...
If you run out of options you can consider using ViewState variables to store your variables.
Read about State Variables
精彩评论