Page_Load 中的数据库请求
在 Page_Load
中,我创建动态控件(带有复选框的表格)。复选框的数量取决于我从数据库中检索的一些信息。我不想在每次回发时都连接到数据库。保存所需变量的最佳方法是什么?也许我需要将它们存储在 HiddenField
中?
In Page_Load
I create dynamic controls (table with checkboxes). Number 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
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将它们存储在视图状态中,这或多或少存储在隐藏字段中(因为视图状态本身被持久化到隐藏字段)
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
在这种情况下,建议从数据库获取变量值。但是,如果您选择不遵循建议,如果您的系统没问题,您仍然可以将这些值存储为会话状态变量...
如果您没有其他选择,您可以考虑使用 >ViewState 变量来存储变量。
了解状态变量< /a>
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