Dynamically adding controls to a page
-
Hello all, I have a page that has a number of items on it (ImageButtons, to be exact). When an image button is clicked, it posts back and I use the ModalPopupExtender to bring up a modal dialog that can contain a user control that is loaded dynamically, depending on what was clicked. After a button on the modal popup is clicked, I need to save changes into a hidden field on the form. However, after postback, the control is totally gone. How do I need to recover the data that was in the form?
-
Hello all, I have a page that has a number of items on it (ImageButtons, to be exact). When an image button is clicked, it posts back and I use the ModalPopupExtender to bring up a modal dialog that can contain a user control that is loaded dynamically, depending on what was clicked. After a button on the modal popup is clicked, I need to save changes into a hidden field on the form. However, after postback, the control is totally gone. How do I need to recover the data that was in the form?
Your control needs to be created every time, and it won't have viewstate unless it's created before page load. I'd use a hidden control to track data from the control, and what controls exist.
Christian Graus Driven to the arms of OSX by Vista.
-
Your control needs to be created every time, and it won't have viewstate unless it's created before page load. I'd use a hidden control to track data from the control, and what controls exist.
Christian Graus Driven to the arms of OSX by Vista.
Another option would be to use the viewstate to track data from the control. You just have to manually set the data in the viewstate. I prefer this method because you can store any serializable object in the viewstate, so it gives you more control over how the data is stored. Plus, you can use viewstate encryption to encrypt the data and prevent users from seeing the contents.