Facebook Invite Friends for ASP.NET

Facebook Invite ASP.NET control is used to send invite requests to friends, to use Facebook application or Facebook Connect web site. To send an invite requests is very useful feature for sharing awareness about Facebook application. It is usually used when users of an application don't want to just share info about application, but they want for their friends to join. Facebook Invite is frequently used in games to invite friends to join game. That is usually rewarded with some points to user who invited them, and it enables him to cooperate with his friends in game too. There are 2 types of Facebook Invite Friends ASP.NET control: the classic one and the small (condensed) one. The classic one is usually bigger in size and it displays pictures of user's friends. Small one contains just a list of friends' names. However, there are properties to set height and width (number of rows and columns) for both of them.

This control is a wrapper around XFBML tags and is adapted to be used as ASP.NET control. The control has just a few properties which have to be set using pure .NET objects for the control to work properly. In following text, there are pictures of both ASP.NET controls, list of properties and code examples. First, the classic one is described, and after it, the small (condensed) one. Both invite friends controls don't have any event handlers which can be executed when friends are invited because XFBML tags does not have JavaScript method which is called in this case. Instead of event handler, the controls have different methods to get info about invited friends. This is explained in the last section of this page.

Compiled version and source code version of both Invite Friends ASP.NET controls, both in C# and VB.NET programming languages, are available as part of Facebook iFrame ASP.NET library and Facebook Connect ASP.NET control library.




Facebook Invite Friends Classic

Following text is describing classic type of Facebook Invite Friends ASP.NET control. Here you can find picture of the control, instructions how to configure it, and code examples. After this section, there is the same section about small type of the control.


Picture of the control:

Following picture shows screenshot of classic invite friends control with request preview opened. It is created with minimal required setting. Pictures of friends and last names are hidden because of privacy protection.

invite




Facebook Invite Friends classic ASP.NET control has a demo page inside Demo Website that shows how it works. The most important fact is that the Demo website is contained in the package with the library, which is very useful resource for code examples, in both C# and VB.NET, for each control from the library. Look at the Facebook Invite Friends classic demo



Configuration

Configuration of the Facebook Invite Friends ASP.NET control is done in ASPX page by setting mandatory and optional properties. If dynamic setting of properties is required, they can be also set in the code behind, for example on Page_Load method. Following tables contains the list of mandatory and optional properties. First 2 properties are mandatory and if they are not set control will throw an exception on page load.


Mandatory Properties:
facebook login button asp.net
Property Name
Type
Description
facebook login button asp.net
MainTitle
String
Main title of control is text which placed at top of control dialog.
facebook login button asp.net
Content
String
Text which is shown in invite request. It is very important to write something attractive to invoke user to accept the request to try a Facebook application or visit a website.

Optional Properties:
facebook login button asp.net
Property Name
Type
Description
facebook login button asp.net
ActionUrl
String
URL where application is redirected after invite requests are sent. If it is not set, value is taken from web.config key 'AppUrl'.
facebook login button asp.net
AcceptUrl
String
When user accept invite request it will be redirected on defined URL. If the property is not set, value is taken from ActionURL property.
facebook login button asp.net
AppName
String
Application name displayed on send button and invite request title. If it is not set, value is taken from web.config key 'AppName'.
facebook login button asp.net
ShowBorder
Bool
If border has to be shown. Default value is true.
facebook login button asp.net
EmailInvite
Bool
If email section has to be shown inside control. The section is not shown if ImportExternalFriends property is set to true. Default value is true.
facebook login button asp.net
ImportExternalFriends
Bool
Show dialog for import external friends from email and other services after Facebook friends are selected for invite. Default value is true.
facebook login button asp.net
Rows
Int
Number of rows. Default value is 5.
facebook login button asp.net
Columns
Int
Number of columns. Default value is 5.
facebook login button asp.net
ExcludeFriends
String
Comma separated value string of friend IDs which should not to be in invite list.
facebook login button asp.net
ExcludeFriendsList
List
List of friend IDs which should not to be in invite list.




Usage Examples:

Following examples show registration and insertion of Facebook Invite Friends classic ASP.NET control inside ASPX page. The first example shows the control with minimal (only two) mandatory properties set, while the second one shows the control with all properties set. Two properties are excluded from setting in ASPX (ExcludeFriends and ExcludeFriendsList) because they depend on list of user's friends and selection of exclusion, so they cannot be set statically in ASPX. Since both properties have the same purpose, but for different value types, example in the code behind shows just the setting of ExcludeFriendsList from list of user’s friends whose name starts with 'A'. For this purpose, Facebook Graph API method from Facebook C# SDK is used to get the list of user friends.

Examples of ASPX files show only the code required for registration and integration of ASP.NET control in a web page. To see all requirements for registered components, including JavaScript, CSS style and header setting, please look at the manual for page requirements. For following examples, all page requirements are placed in ASP.NET master page. Important parts for registration and integration of Facebook Invite Friends control inside ASP.NET page are highlighted.


Minimal properties:
 <%@ Page MasterPageFile="~/Master.Master" AutoEventWireup="true" Inherits="FVK_Demo.InviteFriends" %>
 <%@ Register TagPrefix="fvk" TagName="invite" Src="~/FVK/InviteControl.ascx" %>
 <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>Facebook Connect Invite Friends Control for ASP.NET</title>
    <meta name="description" content="ASP.NET Invite Friends control for Facebook Connect web sites." />
 </asp:Content>
 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <fvk:invite ID="invite1" runat="server"
        MainTitle = "Facebook Visual Kit"
        Content = "Facebook Visual Kit is a set of ASP.NET user controls that facilitate ... "
    />
</asp:Content>


All properties:
 <%@ Page MasterPageFile="~/Master.Master" AutoEventWireup="true" Inherits="FVK_Demo.InviteFriends" %>
 <%@ Register TagPrefix="fvk" TagName="invite" Src="~/FVK/InviteControl.ascx" %>
 <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>Facebook Connect Invite Friends Control for ASP.NET</title>
    <meta name="description" content="ASP.NET Invite Friends control for Facebook Connect web sites." />
 </asp:Content>
 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <fvk:invite ID="invite1" runat="server"
        MainTitle = "Facebook Visual Kit"
        Content = "Facebook Visual Kit is a set of ASP.NET user controls that facilitate ... "
        ActionUrl = "http://apps.facebook.com/someapp/Page1.aspx"
        AcceptUrl = "http://apps.facebook.com/someapp/Page2.aspx"
        AppName = "My Application Name"
        Rows = "3"
        Colums = "3"
        EmailInvite = "false"
        ImportExternalFriends = "false"
    />
</asp:Content>


Set excluded friends in C#:
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;
 using System.Web.UI;
 using System.Web.UI.WebControls;
 using Facebook;
 using FVK;

 namespace FVK_Demo
 {
    public partial class InviteFriends : System.Web.UI.Page
    {
       protected void Page_Load(object sender, EventArgs e)
       {
          if (!Page.IsPostBack)
          {
             FacebookApp facebook = new FacebookApp();
             if (facebook.Session != null)
             {
                IList excludedFriends = new List();
                JsonObject friendsData = (JsonObject)facebook.Api("me/friends");
                JsonArray friendsList = (JsonArray)friendsData["data"];
                foreach (JsonObject f in friendsList)
                {
                   long id = Int64.Parse((string)f["id"]);
                   string name = (string)f["name"];
                   excludedFriends.Add(id);
                }
                invite1.ExcludeFriendsList = excludedFriends;
             }
          }  
       }
    }
 }


Set excluded friends in VB.NET:
 Imports System.Collections.Generic
 Imports System.Linq
 Imports System.Web
 Imports System.Web.UI
 Imports System.Web.UI.WebControls
 Imports Facebook
 Imports FVK

 Namespace FVK_Demo
    Public Partial Class InviteFriends
       Inherits System.Web.UI.Page
       Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
          If Not Page.IsPostBack Then
             Dim facebook As New FacebookApp()
             If facebook.Session IsNot Nothing Then
                Dim excludedFriends As IList(Of Long) = New List(Of Long)()
                Dim friendsData As JsonObject = DirectCast(facebook.Api("me/friends"), JsonObject)
                Dim friendsList As JsonArray = DirectCast(friendsData("data"), JsonArray)
                For Each f As JsonObject In friendsList
                   Dim id As Long = Int64.Parse(DirectCast(f("id"), String))
                   Dim name As String = DirectCast(f("name"), String)
                   excludedFriends.Add(id)
                Next
                invite1.ExcludeFriendsList = excludedFriends
             End If
          End If
       End Sub
    End Class
 End Namespace




Facebook Invite Friends Condensed

Following text is describing small (condensed) type of Facebook Invite ASP.NET control. Here you can find a picture of the control, instructions on how to configure it, list of properties with descriptions, and code examples.


Picture of the control:

Following picture shows screenshot of small invite friends control with 3 friends selected for invite, and it is created with minimal required setting. Last names of user's friends are hidden because of privacy protection.

facebook invite friends condensed




Facebook Invite Friends small ASP.NET control has a demo page inside Demo Website that shows how it works. The most important fact is that the Demo website is contained in the package with the library, which is very useful resource for code examples, in both C# and VB.NET, for each control from the library.Look at the Facebook Invite Friends small demo



Configuration

Configuration of the Facebook Invite control is done in ASPX page since usually all properties are static. If dynamic setting of properties is required, they can be also set in the code behind, for example on Page_Load method. Following tables contains the list of mandatory and optional properties. First property is mandatory and it has to be set. If it is not, an exception is thrown on page load.


Mandatory Properties:
facebook login button asp.net
Property Name
Type
Description
facebook login button asp.net
Content
String
Text which is shown in invite request. It is very important to write something attractive to invoke user to accept the request to try an Facebook application or visit website.

Optional Properties:
facebook login button asp.net
Property Name
Type
Description
facebook login button asp.net
ActionUrl
String
URL where application is redirected after invite requests are sent. If it is not set, value is taken from web.config key 'AppUrl'.
facebook login button asp.net
AcceptUrl
String
When user accept invite request it will be redirected on defined URL. If the property is not set, value is taken from ActionURL property.
facebook login button asp.net
AppName
String
Application name displayed on send button and invite request title. If it is not set, value is taken from web.config key 'AppName'.
facebook login button asp.net
Width
Int
Width of control in pixels. Default value is 300.
facebook login button asp.net
UnselectedRows
Int
Number of rows for unselected friends. Default value is 6.
facebook login button asp.net
SelectedRows
Int
Number of rows for selected friends. Default value is 5.
facebook login button asp.net
ExcludeFriends
String
Comma separated value string of friend IDs which should not to be in invite list.
facebook login button asp.net
ExcludeFriendsList
List
List of friend IDs which should not to be in invite list.




Usage Examples:

Following examples show registration and insertion of Facebook Invite Friends condensed ASP.NET control inside ASPX page. The first example shows the control with minimal (only one) mandatory properties set, while the second one show the control with all properties set, except of setting the list of excluded friends. However, an example of this property’s setting is shown for Invite Friends classic control and it is also valid for this control.

Examples of ASPX files show only the code required for registration and integration of ASP.NET control in a web page. To see all requirements for registered components, including JavaScript, CSS style and header setting, please look at the manual for page requirements. For following examples, all page requirements are placed in ASP.NET master page. Important parts for registration and integration of Facebook Invite Friends control inside ASP.NET page are highlighted.


Minimal properties:
 <%@ Page MasterPageFile="~/Master.Master" AutoEventWireup="true" Inherits="FVK_Demo.InviteFriends" %>
 <%@ Register TagPrefix="fvk" TagName="invite" Src="~/FVK/InviteSmallControl.ascx" %>
 <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>Facebook Connect Invite Friends Control for ASP.NET</title>
    <meta name="description" content="ASP.NET Invite Friends control for Facebook Connect web sites." />
 </asp:Content>
 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <fvk:invite ID="invite1" runat="server"
       Content = "This is a content of Invite request."
    />
</asp:Content>


All properties:
 <%@ Page MasterPageFile="~/Master.Master" AutoEventWireup="true" Inherits="FVK_Demo.InviteFriends" %>
 <%@ Register TagPrefix="fvk" TagName="invite" Src="~/FVK/InviteSmallControl.ascx" %>
 <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>Facebook Connect Invite Friends Control for ASP.NET</title>
    <meta name="description" content="ASP.NET Invite Friends control for Facebook Connect web sites." />
 </asp:Content>
 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <fvk:invite ID="invite1" runat="server"
        Content = "This is a content of Invite request. "
        ActionUrl = "http://apps.facebook.com/someapp/Page1.aspx"
        AcceptUrl = "http://apps.facebook.com/someapp/Page2.aspx"
        AppName = "My Application Name"
        Width = "400"
        UnselectedRows = "10"
        SelectedRows = "10"
    />
</asp:Content>




How to get invited friends?

After friends are invited, or invitation is canceled ('Skip' button is pressed), Facebook Invite Friends ASP.NET control will make redirect to page defined in ActionUrl property. Inside the code behind this page, it is possible to get invited friends' IDs (empty string if skip is made). Friends’ IDs are sent using HTML GET method. Because of that, it is possible to get them by calling QueryString on current Request object. Following code examples show how to get friends' IDs and how to get friends' names by calling FQL query using Facebook C# SDK.



Get Invited friends with C#:
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Web;
 using System.Web.UI;
 using System.Web.UI.WebControls;
 using Facebook;

 namespace FVK_Demo
 {
    public partial class InvitedFriends : System.Web.UI.Page
    {
       IList<string> friendNames = new List<string>();

       protected void Page_Load(object sender, EventArgs e)
       {
          if (!Page.IsPostBack)
          {
             string friendIds = Request.QueryString["ids[]"];
             if (friendIds != null)
             {
                FacebookApp facebook = new FacebookApp();
                string query = "select name from user where uid in (" + friendIds + ")";
                JsonArray friendsArray = (JsonArray)facebook.Query(query);
                foreach (JsonObject f in friendsArray)
                {
                   friendNames.Add((string)f["name"]);
                }
             }   
          }
       }
    }
 }



Get Invited friends with VB.NET:
 Imports System.Collections.Generic
 Imports System.Linq
 Imports System.Web
 Imports System.Web.UI
 Imports System.Web.UI.WebControls
 Imports Facebook

 Namespace FVK_Demo
    Public Partial Class InvitedFriends
       Inherits System.Web.UI.Page
       Private friendNames As IList(Of String) = New List(Of String)()

       Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
          If Not Page.IsPostBack Then
             Dim friendIds As String = Request.QueryString("ids[]")
             If friendIds IsNot Nothing Then
                Dim facebook As New FacebookApp()
                Dim query As String = "select name from user where uid in (" & friendIds & ")"
                Dim friendsArray As JsonArray = DirectCast(facebook.Query(query), JsonArray)
                For Each f As JsonObject In friendsArray
                   friendNames.Add(DirectCast(f("name"), String))
                Next
             End If
          End If
       End Sub
    End Class
 End Namespace

 

Customer Testimonials

"We are using FVK to create Facebook games and applications on the .NET platform, taking advantage of the encapsulated behaviors (like Stream Publish, Invitation, Alert Publishing, etc.) included in the library. FVK has a real good cost-benefits relation, in comparision to develop our own Facebook .Net componentes and UI Controls. It's the best alternative for Facebook & C#."

Ignacio J. Raffa, CTO, Solotuweb

Customer Spotlight



Vote for your favorites

Facebook development platform