在 page_load 中加载所述 ascx 控件时,在回发之间维护自定义控件 (ascx) 状态时出现问题
我正在托管它的页面的 page_load 中加载自定义 ascx 控件。 这会造成各种回发问题。主要是,控件(文本框、下拉菜单等)状态在事件处理程序可以处理它们之前被重置。
有没有人有任何好的例子来说明我如何处理这个问题?
我的网站设计可以看到
在之前的问题中我被告知我可以让控件管理自己的状态。
I am loading a custom ascx control in page_load of the page that hosts it.
This creating all sorts of issues with postbacks. Mainly, control (textboxes, dropdowns,etc) states are getting reset before the event handlers can process them.
Does any one have any good examples of how I could handle this?
My site design can be seen here.
I've been told in a previous question that I can let the control manage its own state.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题已经被问过很多次了。看看这个例子:在验证器上设置 ControlToValidate
This has been asked so many times. Take a look at this for example: Setting the ControlToValidate on a Validator
视图状态在页面加载事件之前恢复,因此需要在页面加载事件之前加载动态控件并将其添加到页面,否则它们的状态将不会按您的预期恢复。请在 Init 事件中执行此操作。
Viewstate is restored before the page load event, and therefore dynamic controls need to be loaded and added to the page before the page load event or their state won't be restored as you expect. Do it in the Init event instead.