|
Dom
|
 |
« on: May 11, 2011, 08:38:53 AM » |
|
tl; dr - Does anyone know how to maintain properties of dynamically generated controls across page postbacks?
Hi all,
Got an issue with a VB.NET page of mine.
Basically, when it loads, it reads an XML file and displays a list of the products listed in the XML file. Each product has a picture, a title, and a description. Each and every product is displayed on the webpage, so the more products that are added to the XML file, the more products are displayed on the webpage.
That much is done and sorted, the trouble is that the user needs to be able to add new products to the XML file. To do this, they click an "Add Product" button, which posts back the page and displays a new set of textboxes for the user to be able to enter a title, description, and location for the image.
Again, that much is working, but when the page posts back after the user clicks "Add Product", the images that have already been generated disappear.
I know that dynamically created controls don't persist across postbacks, so you have to recreate the controls in the Page_Load event each time the page posts back so that the page loads the text into the right boxes again, but for some reason it doesn't seem to load certain properties of certain controls, and the ImageUrl property of an image control seems to be one of them.
Does anyone know how to maintain properties of dynamically generated controls across page postbacks? Simply recreating a textbox on Page_Load is enough to have the page put the text it contained back in that box, but recreating an image control doesn't seem to allow the page to set the properties of that image. So whenever the user clicks "Add Product", the page reloads and the pictures disappear.
Any thoughts? It's a real pain in the bum. Cheers!
|