开发者

Facebook Like button not rendering inside a reloaded GridView

I have a fb:like button inside the GridView and GridView is inside the update panel. The first time of page load the fb:like button showing but when we click the开发者_如何学运维 next button, on the next page the fb:like button doesn't render. Any idea what's wrong?


Due to the fact that you are updating the page with an update panel, the like button will not be rendered when only part of the page is updated. You will have to attach to the clientside updated event (in JS) and then trigger the Facebook XFBML render command:

FB.XFBML.parse();

more about this here: http://developers.facebook.com/docs/reference/javascript/FB.XFBML.parse/

You can do this using the following code:

<script type="text/javascript">

var prm = Sys.WebForms.PageRequestManager.getInstance();
prm.add_pageLoaded(pageLoaded);

var _panels, _count;

function pageLoaded(sender, args)
{
    if (_panels != undefined && _panels.length > 0)
    {
        for (i=0; i < _panels.length; i++)
            _panels[i].dispose();
    }

    var panels = args.get_panelsUpdated();

    if (panels.length > 0)
    {

        updateFbLike();
    }
}

function updateFbLike()
{
    FB.XFBML.parse();
}


</script>

this is taken from this article:

http://msdn.microsoft.com/en-us/magazine/cc163413.aspx


Richard's solution worked fine for me. I shortened the code to:

Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandlerBerliner);
function EndRequestHandlerBerliner(sender, args) {
    if (args.get_error() == undefined) {
        FB.XFBML.parse();
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜