如何正确处理复合控件中子控件的视图状态?
我有一个包含 ListBox 子控件的复合控件。 回发时,列表框的项目消失。 我有一个用于初始化 ListBox 的属性,并将其添加到 CreateChildControls 中的控件集合中。 难道我做错了什么? 我是否需要做其他事情才能正确处理此列表框的视图状态?
I have a composite control that contains a ListBox child control. On postback, the items for the ListBox disappear. I have a property for the ListBox that initializes it, and I add it to the controls collection in CreateChildControls. Am I doing something wrong? Do I need to be doing something else to properly handle the viewstate of this ListBox?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在添加列表项或数据绑定之前,请务必将控件添加到父级。 否则,复合控件将不会跟踪列表框列表项上的视图状态。
这是更彻底的解释: http://scottonwriting.net/sowblog/posts/2129.aspx< /a>.
Be sure to add your control to the parent before you add listitems or databind. Otherwise, your composite control won't track viewstate on your ListBox's listitems.
Here's a more thorough explanation: http://scottonwriting.net/sowblog/posts/2129.aspx.