0

一直在拉我的头发并在网上做一些查看,试图找出一个优雅的解决方案来解决我的问题。

我有一个 ProductImages.aspx 页面。它在动态创建的列表中显示与该产品关联的所有图像。事件与每张图片相关联,以便您对其进行更新。

这工作正常。

但是,最后我有一个选项可以让我添加新图像。这是一个触发对 AddImage 方法的调用的按钮。

现在发生的事情是原始控件正在创建并添加到带有事件的页面中。然后如果触发按钮事件,它将重新创建所有现有的图像控件和一个新的。添加这一点,在 OnInit 之后创建的新图像控件没有附加事件,因为事件是在 OnInit 之后添加的。

我可以执行 Response.Redirect 来重新加载页面并触发 OnInit 以再次连接事件,但这似乎非常不雅,并且破坏了使用更新面板的意义。

有任何想法吗?

4

2 回答 2

1

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.

于 2009-05-08T20:16:58.483 回答
0

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.

于 2009-09-01T20:08:17.417 回答