自定义服务器控件内中继器内的文本框丢失值

发布于 2024-10-10 10:42:50 字数 134 浏览 0 评论 0原文

我正在开发我的第一个自定义服务器控件,它将显示带有文本框的字段列表。当包含此自定义服务器控件的页面回发时,文本框中的值将丢失,因为转发器被重新绑定,或者视图状态未保留这些值。

如何让中继器在回发之间保存文本框的值?

干杯!

I am developing my first Custom Server Control which will display a list of fields, with textboxes. When the page containing this custom server control is posted back, the values inside the textbox are lost as the repeater is either re-binded, or the viewstate isn't holding onto the values.

How can I get the repeater to hold the values of the textboxes between postbacks?

Cheers!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

国际总奸 2024-10-17 10:42:50

您很可能没有在页面生命周期的正确阶段重新创建自定义控件。 Viewstate 在生命周期的 OnInit() 事件之后立即恢复。因此,如果您在此之后添加控件,则该控件将无法恢复视图状态。

尝试将动态控件的创建移至页面的 OnInit() 事件。

Most likely you are not re-creating your Custom Control at the right stage of the page lifecycle. Viewstate is restored right after the OnInit() event of the lifecycle. So if you are adding the control after this, the control is not there for the Viewstate to be restored.

Try moving the creation of your dynamic control to the OnInit() event of the page.

久而酒知 2024-10-17 10:42:50

如果您动态填充中继器? 那么您可能会遇到基于视图状态加载时间的计时创建问题

尝试将所有动态控件创建放入 Page_Init 事件中,以防止时序创建问题

即不使用 Page_Load 事件,而使用 Page_Init 事件在控件中动态绑定数据。

protected void Page_Init(object sender, EventArgs e){ ..... }

问候,我希望我有所帮助

If you dynamically populate your repeater? then you might have a timing creation issue based on when View state is loaded.

Try putting all your dynamic control creation into the Page_Init event to preven the timing creation issue.

ie instead of using the Page_Load event use Page_Init event to bind data dinamically in your control.

protected void Page_Init(object sender, EventArgs e){ ..... }

regards, I hope I have been helpful

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