Thursday, April 16, 2015

ASP.NET WebForms UpdatePanel Partial Postback JavaScript After pageLoad

While working on a legacy app in WebForms, I came across a situation where a Control was not available to JavaScript after a PartialPostback. I took every measure to ensure that the function was called after pageLoad. At first, it was being called OnClientClick. Then I switched it to call during pageLoad, endRequest and every other client event. No matter what I did, both $ and document.getElementById could not find the Control in the DOM. It was like it didn't exist. Either that or the id changed. Turns out the last thing was true. The id changed after the partial. On the first load, the element had a regular id. After the post back it had a ct100....._regularIdPart id. Hmmm...so I switched up the selector to $('[id$=regularId]') which is endswith.

No comments:

Post a Comment