在回发时无法在datagrid中找到动态控件

时间:2021-09-06 21:11:05

Using .NET 1.1, I have a DataGrid that contains three columns for each row.

使用.NET 1.1,我有一个DataGrid,每行包含三列。

Row one has a label with some text.

第一行有一个带有一些文字的标签。

Row three will always have two radio buttons and two checkboxes and those are in the HTML side of the page.

第三行将始终有两个单选按钮和两个复选框,它们位于页面的HTML端。

Row two will have dynamically generated controls (just textboxes for now) and there can be 1 or more per row. These will be used for user input.

第二行将具有动态生成的控件(现在只是文本框),每行可以有1个或更多。这些将用于用户输入。

There is a button on the page and when the user clicks the button I need to update the DataGrid’s source (my DataTable) with the new values from the user’s input.

页面上有一个按钮,当用户单击按钮时,我需要使用用户输入中的新值更新DataGrid的源(我的DataTable)。

The issue is the DataGrid seems to be losing the dynamically generated controls on PostBack. I can loop through each Item in the DataGrid and I can access the radio buttons and the checkboxes, but the textboxes aren’t there.

问题是DataGrid似乎正在丢失PostBack上动态生成的控件。我可以遍历DataGrid中的每个Item,我可以访问单选按钮和复选框,但文本框不在那里。

Any ideas?

2 个解决方案

#1


3  

Remember: every time a postback occurs you are working with a new instance of your page class. Dynamic controls added to the page during a previous postback went to the garbage collector as soon as the page for that postback rendered to the browser, along with the rest of that page instance. You need to re-create your dynamic controls on every postback.

请记住:每次发生回发时,您都在使用页面类的新实例。在上一次回发期间添加到页面的动态控件在该回发的页面与该页面实例的其余部分一起呈现给浏览器时立即进入垃圾收集器。您需要在每次回发时重新创建动态控件。

#2


0  

you have to regenerate the controls. You should be able to get their values from the http request object

你必须重新生成控件。您应该能够从http请求对象中获取它们的值

#1


3  

Remember: every time a postback occurs you are working with a new instance of your page class. Dynamic controls added to the page during a previous postback went to the garbage collector as soon as the page for that postback rendered to the browser, along with the rest of that page instance. You need to re-create your dynamic controls on every postback.

请记住:每次发生回发时,您都在使用页面类的新实例。在上一次回发期间添加到页面的动态控件在该回发的页面与该页面实例的其余部分一起呈现给浏览器时立即进入垃圾收集器。您需要在每次回发时重新创建动态控件。

#2


0  

you have to regenerate the controls. You should be able to get their values from the http request object

你必须重新生成控件。您应该能够从http请求对象中获取它们的值