ASP.net 中关于 WebControl 与 UserControl ViewState 的奇怪行为
好的,我已经解决了我的问题,但我不知道为什么一种类型的控件有效,而另一种则无效。
场景:我正在开发自定义向导样式页面设计,该设计最初完全使用 C# ASP.Net 4.0 中的 UserControl
完成。您正在查看的步骤是通过控制可见性在服务器端进行控制的。
我的问题:我不喜欢UserControl
并希望尽可能多地使用WebControl
,尽管不值得我花精力重做整个过程与 WebControl
一样,需要新的控件来扩展功能。
我最初的解决方案:我最初开始根据需要创建WebControl
。这工作得很好,直到我距离给定的 WebControl
两步,它失去了它的 ViewState
。至少我相信这就是发生的事情。这是一个 CheckBoxList
,当我离开 2 步时,ListItems
就消失了。
最终解决方案:重新创建与UserControl
相同的控件我始终可以访问CheckBoxList
Items
。
这一切看起来相当合乎逻辑。如果某个控件或其父控件之一不可见,则它不会包含在 ViewState
数据中。我想真正的问题是,为什么 UserControl
有效?
Ok, I've solved my problem but I don't know why one type of control works and another doesn't.
The scenario: I'm working on a custom wizard style page design that was originally done completely with UserControl
s in C# ASP.Net 4.0. The step that you are viewing is controlled on server side via control visibilty.
My problem: I dislike the UserControl
s and want to use WebControl
s as much as possible, though it's not worth my effort to redo the entire thing with WebControl
s, and new controls are needed to expand the functionality.
My original solution: I initially started creating WebControl
s as needed. This worked fine until I got 2 steps away from a given WebControl
, where it lost it's ViewState
. At least I believe that is what happened. It was a CheckBoxList
and as soon as I was 2 steps away, the ListItems
disappeared.
The final solution: Recreating the same control as a UserControl
I always have access to the CheckBoxList
Items
.
This all seems fairly logical. If a control or one of it's parent's is not visible, it won't be included in the ViewState
data. I guess the real question is, why does UserControl
work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论