回发时未选中 ASP.NET 复选框
我有一个 ASP.NET Web 表单。其中有一个简短的复选框列表。我期望发生的是我选中几个复选框,进行回发,并且在回发后这些复选框应保持选中状态。
由于某种原因,回发时复选框未被选中。我在 page_init 或 page_load 事件中没有对复选框进行任何操作。当我在调试时单步执行代码时,复选框会被标记为已选中。
我尝试将回发时检查属性的值设置为 true,但复选框仍然没有被检查。
有人以前见过这个并对如何解决它有什么建议吗?
编辑
我一开始没有意识到 - 复选框是 html 服务器控件(输入 type=checkbox runat=server...)。
I have an ASP.NET web form. In it is a short list of checkboxes. What I expect to have happen is I check a couple checkboxes, do a postback, and the checkboxes should remain checked after the postback.
For some reason, the checkboxes are unchecked on postback. I've got nothing in the page_init or page_load events that do anything with the checkboxes. And when I step through the code while debugging, the checkboxes are flagged as checked.
I tried setting the value of the checked property on postback to true, but the checkboxes still don't wind up checked.
Anyone seen this before and have any suggestions on how to fix it?
EDIT
I didn't realize at first - the checkboxes are html server controls (input type=checkbox runat=server...).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要重写 SaveViewState 和 LoadViewState 方法 - 并将复选框值放入 ViewState 中。
https://web.archive.org/web/20211020153240/https://www.4guysfromrolla.com/articles/110205-1.aspx
You need to override the SaveViewState and LoadViewState methods - and place the checkbox values into ViewState.
https://web.archive.org/web/20211020153240/https://www.4guysfromrolla.com/articles/110205-1.aspx