Wednesday, March 28, 2012

Viewing Source - Javascript error on missing elements

Hello,

I know this is very likely to be my misunderstanding of how ajax works, but any help would be greatly appreciated.

When my page first loads there is a panel that is not visible, inside the UpdatePanel. After a partial postback this panel becomes visible, but when I 'View Source', the outputted code for the panel does not exists, nor the code for its child controls (even though they show on screen). This means when I try to use client-side code for a control in that panel, eg.

var t = window.document.getElementByID(childID);

it cannot be found as the childID doesn't appear in the source.

Any ideas?

Thanks very much.

Simon

This is actually expected... View/Source in the browser only displays the source that was sent down with the original request.

As for your specific issue, make sure you're using the client ID... a common idiom is: $get('<%= MyControl.ClientID %>'). $get() is a shortcut in ASP.NET AJAX for document.getElementByID().

No comments:

Post a Comment