views:

2407

answers:

4

I have a Fancybox (or more accurately) a number of fancy boxes on an asp.net page.

My Fancybox (jquery plugin) works fine until a postback occurs on the page then it refuses to work.

Any thoughts? Anyone experienced similar behaviour?

UPDATE : Some Code..

I have a databound repeater with a fancybox on each repeating item.

They are instanciated by (outside the repeater)

$(document).ready(function() {
            $("a.watchvideo").fancybox({
            'overlayShow': false,
            'frameWidth' : 480,
            'frameHeight' : 400
            });
        });

The anchor tag is repeated..

href="#watchvideo_<%#Eval("VideoId")%>"

As is a div with

id="watchvideo_<%#Eval("VideoId") %>

As is a script element that instanciates the flash movies

Yes the VideoIds are being output the the page.

UPDATE : It's not a problem with the flash..

It is not a problem with the flash as i've tried it without the flash, it wont even pop a window with a simple message in.

UPDATE : I wonder if it is the updatepanel.

http://stackoverflow.com/questions/301473/rebinding-events-in-jquery-after-ajax-update-updatepanel

-- lee

+1  A: 

Could it be that the instantiating code is being inserted at a piece of code which is not run after a postback?

Ropstah
Interesting.. the fancybox instanciating code is on the aspx page.. I might try writing it to the page from the code behind..
Lee Englestone
Tried it. No joy :-(
Lee Englestone
A: 

It was the Update panel as described

here.. http://stackoverflow.com/questions/301473/rebinding-events-in-jquery-after-ajax-update-updatepanel

As suggested I simply replaced

$(document).ready(function() {
            $("a.watchvideo").fancybox({
            'overlayShow': false,
            'frameWidth' : 480,
            'frameHeight' : 400
            });
        });

with

function pageLoad(sender, args)
{
   if(args.get_isPartialLoad())
   {
       $("a.watchvideo").fancybox({
            'overlayShow': false,
            'frameWidth' : 480,
            'frameHeight' : 400
            });

   }
}

and it worked!

-- Lee

Lee Englestone
+5  A: 

The problem is in using $(document).ready() to bind the fancybox. This code is only executed once, when the page is originally loaded. If you want the fancybox functionality on every postback, synchronous or asynchronous, replace the $(document).ready() with pageLoad(sender, args). i.e.

function pageLoad(sender, args) {
        $("a.watchvideo").fancybox({
        'overlayShow': false,
        'frameWidth' : 480,
        'frameHeight' : 400
        });
}

see this answer for more info

Russ Cam
Cheers Russ, looks like you would have solved my problem had I not got there on my own. Much appreciated. Cheers,-- Lee
Lee Englestone
No probs, glad to help. I highly recommend looking into the links on the other answer - the article is a good read and the ASP.NET AJAX documentation can prove extremely useful.
Russ Cam
Thanks I just had this issue to and I'm not well versed on jQuery yet. This solved it! Thanks so much for posting this.
Frank Hale
A: 

This might help someone else, but FancyBox appends it's code to the <body> element... which is all fine and well, but resides OUTSIDE the asp.net <form> element. My postback problems went away when I modified FancyBox to append its dom objects to the <form> element:

$('body form:first').append( ... );