My problem is that I have an ASPX page which contains an ASP:Table. The rows for the table is added dynamically on Page_Load. One column in the table contains TextBoxes, BUT when I type someth开发者_如何学运维ing on a TextBox and cause a postback, I am unable to find the value just entered. And above that the table is not displayed after the postback.
Can anyone help me please? I want to keep the table viewstate with the modified textbox values, so that when i post back to server, I can intercept these new values.
Thanks in advance, Kevin
You will need to ensure you re-create the textboxes with the same IDs, and then you should be able to find the value. For example, if you are using TextChanged
events, these will fire so-long as the textboxes are re-created each time and have the same IDs.
Are the rows of the table (or the table itself) added at every Page_Load? They should be, if you want them to work correctly between postbacks.
Edit: With the same IDs, as another answer pointed out.
Dynamic controls need to be added during the Init event (and on every load) if you want ViewState to track anything, because ViewState is restored before Page_Load.
However, TextBox values are found in the post data, not the Viewstate. This is a common misconception. The same rule applies though.
精彩评论