Web 控件的视图状态去了哪里?
TextBox
是一个 WebControl
,它是一个具有 ViewState
属性的 Control
。
那么为什么当我输入“.”时在 myTextBox
之后 ViewState 属性不会出现在属性和方法列表中吗?
A TextBox
is a WebControl
which is a Control
which has a ViewState
property.
So why when I type '.' after myTextBox
doesn't the ViewState property appear in the list of properties and methods?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它适用于需要保持视图状态的自定义控件,而不是用于外部修改。它受到
保护
(即只能从派生对象访问)是有原因的。例如,如果您创建了一个滑块控件来保留其所在位置的视图状态,则需要使用
ViewState
属性。但是没有其他任何理由使用滑块控件的视图状态。It's for use with custom controls that need to keep a viewstate, not for external modification. It's
protected
(i.e. only accessible from derived objects) for a reason.For example, if you created a slider control that kept a viewstate for which position it was at, you would need to use the
ViewState
property. But there's no reason for anything else to use your slider control's viewstate.您看不到它,因为它受到保护。
下面是来自元数据的属性:
与 ViewState StateBag 的交互是通过 SaveViewState 和 LoadViewState 方法处理的,这些方法也受到保护,并且只能由控件访问。
您不需要对控件的 ViewState 执行任何操作。它会自我维护。但是,您确实可以访问页面上的 ViewState。
You can't see it because it's protected.
Here's the property from metadata:
Interaction with the ViewState StateBag is handled through the SaveViewState and LoadViewState methods, which are also protected and only accessible to the control.
You should not need to do anything with the control's ViewState. It will maintain itself. You do however have access to the ViewState on the page.