Tuesday, December 14, 2010

Sys.InvalidOperationException: Could not find UpdatePanel with ID 'xxx'

Recently, I was working on an AJAX UpdatePanel with multiple triggers. I noticed I received the following JavaScript error in IE7, but not FireFox:

'Sys.InvalidOperationException: Could not find UpdatePanel with ID 'xxx'. If it is being updated dynamically then it must be inside another UpdatePanel.'

My page was written as follows (with each trigger on its own line (to make it readable)):

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate></ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnImg1" EventName="Click" />

<asp:AsyncPostBackTrigger ControlID="btnImg2" EventName="Click" />

<asp:AsyncPostBackTrigger ControlID="btnImg3" EventName="Click" />

<asp:AsyncPostBackTrigger ControlID="btnImg4" EventName="Click" />
</Triggers>
</asp:UpdatePanel>

I had read that adding the UpdateMode=Conditional and adding an specific EventName to each trigger would maybe resolve my problem, however, it did not, but I left it in just in case.

I had only noticed this problem in IE after I had added the fourth trigger. I also noticed if I removed the fourth trigger, there was no JavaScript error. So I then change my page to the following (put all the triggers on a single line):

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate></ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnImg1" EventName="Click" /><asp:AsyncPostBackTrigger ControlID="btnImg2" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="btnImg3" EventName="Click" /><asp:AsyncPostBackTrigger ControlID="btnImg4" EventName="Click" />
</Triggers>
</asp:UpdatePanel>

This seemed to fix the problem, even moving it to two lines worked. So I guess it was a whitespace issue? Very strange...only in IE!

*note my content template it blank because I'm actually working with a swfobject to play a movie...so there is a lot more code here but I'm only showing the specific area that was broken...