ThickBox 3.1 within ASP.NET UpdatePanel

So, out of the box, this just doesn’t work.  Here’s the situation.

Thickbox works fine before any async postbacks by the updatepanel.  However, once the updatepanel is reloaded (does a postback), thickbox will no longer work and will render your links regular HTML links.

The Reason

The reason for this is when the updatepanel posts back, the javascript is reloaded but is not initialized, nor is it registered with the DCOM.

Solution

Add the following code to the pageLoad method in your AJAX enabled page, so that it looks something like this:

<script type=”text/javascript” language=”javascript”>
function pageLoad()
{
var isAsyncPostback = Sys.WebForms.PageRequestManager.getInstance().get_isInAsyncPostBack();
if (isAsyncPostback) {
tb_init(’a.thickbox, area.thickbox, input.thickbox’);
}
}
</script>

This code will check if there is an async post back being fired, and if so, will re-initialize thickbox.

I search around for at least 4 hours until I was able to piece together some solutions.  This is the best one.

Good luck.

ASP.NET UpdatePanel ATLAS AJAX ThickBox modal iframe

6 Responses to “ThickBox 3.1 within ASP.NET UpdatePanel”

  1. Kent Says:

    Thank you!!! This bit of code solved a HUGE problem for me.

  2. Seb Says:

    This really helped me, thanx a lot !!!

  3. My view of life : 2 linkuri Says:

    […] MouseOverThickBox 3.1 within ASP.NET UpdatePanel Technorati tags: ASP.NET, hyperlink, ajax, thickbox, asp:updatepanel Filed under: ASP.NET, […]

  4. alexandru savu Says:

    Good article. Fixed a bunch of problems.

    There is also a port to a server control here : http://www.dotnet6.com/blogs/erik_lenaerts/archive/2007/07/07/asp-net-thickbox-control.aspx

  5. Jason R Says:

    Thank you very much. A lovely snippet of code which does exactly what it says on the tin. Perfect.

  6. Austin G. Says:

    Huge help, thank you.

Leave a Reply