Web 控件的视图状态去了哪里?

发布于 2024-12-01 06:08:55 字数 188 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

如梦亦如幻 2024-12-08 06:08:55

它适用于需要保持视图状态的自定义控件,而不是用于外部修改。它受到保护(即只能从派生对象访问)是有原因的。

例如,如果您创建了一个滑块控件来保留其所在位置的视图状态,则需要使用 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.

您看不到它,因为它受到保护。

下面是来自元数据的属性:

[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
protected virtual StateBag ViewState { get; }

与 ViewState StateBag 的交互是通过 SaveViewState 和 LoadViewState 方法处理的,这些方法也受到保护,并且只能由控件访问。

您不需要对控件的 ViewState 执行任何操作。它会自我维护。但是,您确实可以访问页面上的 ViewState。

You can't see it because it's protected.

Here's the property from metadata:

[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
protected virtual StateBag ViewState { get; }

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文