Technological Guide.

ASP.Net-How to capture Dynamic controls’ values

In an Asp.net web page if we add controls like textbox dynamically during runtime, we can’t capture the dynamic controls’ values (entered by user) as the controls will be disposed when the page loads and renders with the physical controls only. In order to capture these dynamic controls’ values there exists many techniques, one of them is presented in this post.

Controls like text box or lable which can be created dynamically will exist on the webpage until the next post back happens when all the controls will be submitted back to the form of the webpage. Once the subsequent post back happens the dynamic controls will be disposed and the web page will be rendered to the browser with physical controls only, so any code written to access the dynamic controls will raise an error saying object is null.

Here is the code to create and capture the dynamic controls’ values (entered by user).

A webpage is designed with a Panel to which the dynamic controls will be added during run time upon clicking the button “btnCreate”. After the user enters some data in the dynamically created textbox, the entered text will be captured in the click event of button “btnCapture” and it’ll be written to the same webpage using Response.Write.

You may also like to read

 
 

One Response to “ASP.Net-How to capture Dynamic controls’ values”

  1. BrandX says:

    Nice - this lets me change the number of dynamic controls on the page on each postback as the user changes data.

Leave a Reply