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
July 11th, 2008 at 12:22 am
Thank you!!! This bit of code solved a HUGE problem for me.
August 29th, 2008 at 3:02 pm
This really helped me, thanx a lot !!!
October 24th, 2008 at 6:28 pm
[…] MouseOverThickBox 3.1 within ASP.NET UpdatePanel Technorati tags: ASP.NET, hyperlink, ajax, thickbox, asp:updatepanel Filed under: ASP.NET, […]
October 24th, 2008 at 6:29 pm
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
November 12th, 2008 at 5:55 pm
Thank you very much. A lovely snippet of code which does exactly what it says on the tin. Perfect.
December 5th, 2008 at 8:34 pm
Huge help, thank you.