ASP.NET AJAX嵌套updatePanel modalPopup funkiness

时间:2022-10-07 12:26:40

It seems that in some cases, if you end up with nested modalPopups wrapped with updatePanels (not ideal I know, and should probably be refactored, but that's what we're working with because of how some of the user controls we wanted to re-use were written), when you fire a postback that should open the nested modalPopup, instead it closes the parent one. For the sake of argument, if I set a breakpoint and run

似乎在某些情况下,如果你最终得到用updatePanels包装的嵌套modalPopup(我不知道,并且应该重构,但这就是我们正在使用的,因为我们想要的一些用户控件如何重新当你打开一个应该打开嵌套modalPopup的回发时,它会关闭父对象。为了论证,如果我设置断点并运行

((ModalPopupExtender)this.Parent.Parent.FindControl("modalPopupExtender'sID").Show();

right before the child modalPopup's Show() method is called, it works as we originally expected. It seems to me that, because when updatePanels are nested, they can post back their parent, the parent modalPopup "doesn't know" it's supposed to be showing and reloads its panel's visibility from scratch as false. Because the child modalPopup is then nested inside a parent panel whose visibility is false, calling Show() on it has no effect either. So instead of getting another modalPopup open, the current one closes. This is not an error, just behavior we didn't expect, so it was difficult to track down with no exception thrown anywhere, but I think the above explanation makes sense... If I've understood the problem incorrectly, please clarify it and enlighten me, because this doesn't seem to happen all the time I'd think it would!
At this point for this particular situation we're stuck re-writing some of those controls to not end up with nested updatePanels so this doesn't happen, but I'm curious:
Has anyone run into this problem before, and did you come up with any clever work-around that doesn't involve a call to FindControl() to re-Show() the modalPopup in question?

在调用子modalPopup的Show()方法之前,它就像我们原先预期的那样工作。在我看来,因为当updatePanel嵌套时,他们可以回发他们的父,父modalPopup“不知道”它应该显示并从头开始重新加载其面板的可见性为false。因为子modalPopup然后嵌套在可见性为false的父面板中,所以对它调用Show()也没有效果。因此,不打开另一个modalPopup,而是关闭当前的modalPopup。这不是一个错误,只是我们没想到的行为,所以很难追踪到任何地方没有异常抛出,但我认为上述解释是有道理的...如果我不正确地理解这个问题,请澄清它并且启发我,因为这似乎不会一直发生,我认为它会!在这一点上,对于这种特殊情况,我们不得不重新编写其中一些控件而不是最终使用嵌套的updatePanel,所以这不会发生,但我很好奇:有没有人遇到过这个问题,你来了吗?任何聪明的解决方法,不涉及调用FindControl()重新显示()有问题的modalPopup?

1 个解决方案

#1


3  

I have solved this problem!
If you change the UpdatePanel's UpdateMode to "Conditional", the parent UpdatePanel doesn't post back when the child UpdatePanel posts back, and then nesting them is no issue at all!
I'm not sure why UpdateMode="Always" is the default, but, lesson learned.

我已经解决了这个问题!如果您将UpdatePanel的UpdateMode更改为“Conditional”,则在UpdatePanel子回送后,父UpdatePanel不会回发,然后将它们嵌套完全没有问题!我不确定为什么UpdateMode =“Always”是默认值,但是,经验教训。

#1


3  

I have solved this problem!
If you change the UpdatePanel's UpdateMode to "Conditional", the parent UpdatePanel doesn't post back when the child UpdatePanel posts back, and then nesting them is no issue at all!
I'm not sure why UpdateMode="Always" is the default, but, lesson learned.

我已经解决了这个问题!如果您将UpdatePanel的UpdateMode更改为“Conditional”,则在UpdatePanel子回送后,父UpdatePanel不会回发,然后将它们嵌套完全没有问题!我不确定为什么UpdateMode =“Always”是默认值,但是,经验教训。