Facebook UI Message Friend Dialog

1k views Asked by At

Hi Guys just wondering if you could help, I have a page in C# that should when a button is clicked show the friends dialog to send an information out to them to start using an application.

However I'm having a problem with FB.UI trying to get a modal iframe displaying of the friends list.

Basically it attempts to open the modal iframe it shows the blue facebook frame but no data then after 5 seconds it closes.

can any one help

    <%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/Main.master" AutoEventWireup="true" CodeFile="CompetitionPanel.aspx.cs" Inherits="CompetitionPanel" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <script src="http://connect.facebook.net/en_US/all.js"></script>
    <script>
        FB.init({
            appId: '123',
            status: true, // check login status
            cookie: true, // enable cookies to allow the server to access the session
            xfbml: true,  // parse XFBML
            session: '<%=CurrentSession.AccessToken %>'
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="body" Runat="Server">
<script>

    function test() {
        FB.ui({method: 'apprequests', 
        message: 'You should learn more about this awesome game.', 
        data: 'tracking information for the user',
        display: 'iframe'
    },
   function (response) {
       if (response && response.post_id) {
           alert('Post was published.');
       } else {
           alert('Post was not published.');
       }
   }

     );

        return false; 
    }

</script>
<div id="fb-root"></div>
<div class="container">
    <div class="left">
        <h2>WANT TO WIN FREE KIT?</h2>
        <p>
            Suggest  your friends. At the end of the week, you'll be entered into a prize draw to win free kit. The competition resets every week.
            Simple.
        </p>
        <asp:Button runat="server" ID="btntest" OnClientClick="Javascript:test();"/>
    </div>
    <div class="right"></div>
</div>
</asp:Content>

Thanks in advance.

1

There are 1 answers

0
JCPhlux On BEST ANSWER

When I tested this code it looks like your button is doing a postback. so I changed

<asp:Button runat="server" ID="btntest" OnClientClick="Javascript:test();"/>

to

<asp:Button runat="server" ID="btntest" OnClientClick="return test();"/>

This stoped the postback from happening but the Dialog never populated just like you mentioned in your post.

I am not sure why but it looks like Facebook does not like the return false in your test function so I tried this

<asp:Button runat="server" ID="btntest" OnClientClick="Javascript:test();return false;"/>

and in the test function I commented out the retrun false.

//return false; 

This worked but it was very slow to populate. After some testing it looks like the slowness was dew to the Script section that the function test was in was inside the asp form and on this page I had a script manager so I moved that script section outside the form and it populated a bit faster.

Hope this helps

Cheers