[英]ASP.NET - Dynamic Control Values & Postback
I'm trying to persist the contents of a textbox through a postback, and I've exhausted all of my effort but can't get it working right. 我正在尝试通过回发来保留文本框的内容,我已经花了所有力气,但无法正常工作。
What should happen is: 应该发生的是:
The problem is - the first time the page posts back, it works. 问题是-页面第一次回发时,它可以工作。 Every other postback it resets to the default value of the textbox.
每隔回发一次,它将重置为文本框的默认值。
I have a very similar setup elsewhere, so I'm thinking it might be a minor thing I'd never think of. 我在其他地方也有非常相似的设置,所以我认为这可能是我从未想到的小事。 There's a lot of code, so it might be easier to talk about what to do (load the dynamic control, populate the values etc) rather than how to do it.
有很多代码,因此谈论做什么(加载动态控件,填充值等)比如何做起来容易。
There was actually a bug in my original code which meant it would never have in the way I was using the modified version. 我的原始代码中实际上存在一个错误,这意味着它永远不会像我使用修改后的版本那样。 Apparently state is restored in Page_Load, so any controls need to be initialized by to have their values restored.
显然状态已在Page_Load中恢复,因此需要初始化任何控件以恢复其值。
Creating the control in Page_PreLoad, then populating it after Page_Load solved the problem. 在Page_PreLoad中创建控件,然后在Page_Load解决问题后填充它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.