在 ASP.NET 中访问父页面的视图状态
好吧,我想我在这里遗漏了一些明显的东西,但我仍然无法使它工作......
我在 ASP.NET 中有一个页面。 我在页面中有一个嵌套类。 我在这个嵌套类中有一个属性。 如何从属性的 Set 语句访问页面的视图状态?
谢谢!
OK, I guess I'm missing something obvious here, but I still can't make it work...
I have a page in ASP.NET.
I have a nested class inside the page.
I have a property in this nested class.
How can I access the page's viewstate from the property's Set statement?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你想做什么?你可能采取了错误的方式。听起来页面需要设置此属性,而不是“嵌套类”(顺便说一句,这与您的问题完全无关)。这只是一些任意的物体吗?或者我们真的在谈论用户控件或自定义控件吗?
如果它是某个任意对象...您将需要显式传入 Page/Viewstate 对象作为方法参数,或者公开 Page 可以设置的属性。
What are you trying to do? You are probably going about it the wrong way. It sounds like the Page needs to set this property, not the "nested class" (By the way, this is entirely irrelevant to your problem). Is this just some arbitrary object? Or are we really talking about a user control or custom control?
If it's some arbitrary object... you will need to explicitly pass in the Page/Viewstate object as a method parameter, or expose a property which the Page can set.
Viewstate 是页面内部的;您必须创建一个基页面类,其中包含公开的公共属性。
注意:它是私有的是有原因的:-) 有替代存储来缓存对象,如果对象是可序列化的,则可以直接将对象存储在视图状态中。
HTH。
Viewstate is internal to the page; you would have to create a base page class with a public property exposing this.
Note: there is a reason why it's private :-) There are alternative stores for caching an object, and if an object is serializable, you can directly store the object in viewstate.
HTH.