views:

273

answers:

2

Been pulling my hair out and doing a bit of looking on the web to try and figure out an elegant solution to my issue.

I have a ProductImages.aspx page. It shows all of the images associated with that product in a dynamically created list. Events are wired up to each picture to allow you to update it.

This works fine.

However, I have an option at the end which lets me add a new image. This is a button which fires off a call to the AddImage method.

Now what is happening is that the original controls are being create and added to the page with events. Then the button event if fired which recreates all of the existing image controls and a new one. Add this point the new image control create after the OnInit does not have events attached due to the events being added AFTER the OnInit.

I can do a Response.Redirect to reload the page and fire the OnInit to wire up the events again but this seems very inelegant and destroys the point of using update Panels.

Any ideas?

+1  A: 

I'm thinking you could always load the picture upload control in a div and have a Javascript link to toggle the display attribute of the div.

Or perhaps use CollapsiblePanels from the AjaxToolKit to hide and show the upload form.

I think either of those ways would be more elegant than doing a post back (even if it's in an UpdatePanel) just to retrieve the picture upload form.

rvarcher
A: 

Your questions makes it sound like you're saying that you can't put the controls in OnInit because it is only fired on the first load of the page. This is not the case - OnInit is fired each time the page is loaded (including postbacks), so you can re-create your controls there even when using an update panel.

One property that is different between the initial load and the postbacks is the Page.IsPostback property, which you can use to just perform actions on the first load of the page.

Sam Schutte