Select Facebook Friends for ASP.NETSelect Facebook Friends ASP.NET control is used to provide an easy user interface to get user's friends, and select them for some particular purpose. For example, it can be used in Facebook Gift Application to select friends to whom gift(s) should be sent. On each select, event handler is executed to provide additional action, without the need of press additional buttons to confirm. It can be used to automatically update description of stream publish control or for some similar purpose. The Select Facebook Friends control also has some additional methods to provide filtering and selection from the code behind. There are also properties to configure number of rows and columns of the control. The control has two types of filter methods and three types of selection methods. There is also possibility to change the number of rows and columns. Compiled version and source code version of this ASP.NET control are available in C# and VB.NET programming languages, as part of Facebook ASP.NET (C# and VB.NET) Control library.
Picture of Select Facebook Friends control: Following picture shows Select Facebook Friends ASP.NET control with 4 rows and 3 columns. Selection of 2 friends is already made.
Select Facebook Friends 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
Select Facebook Friends demo
ConfigurationConfiguration of the Select Facebook Friends ASP.NET control is done in ASPX page by setting number of rows and columns. If dynamic setting of properties is required, they can be also set in the code behind, for example on Page_Load method. There is also an event handler which executes when selection is changed. If event handler is used, there should be a method in the code behind to execute additional code when the event is triggered. There are also several methods which can be executed on page load, as part of configuration, or later on user action. Following tables show: the list of all properties with their types and descriptions, the list of all methods with input parameters and descriptions, and one event handler. Properties:
Property Name
Type
Description
Rows
Int
Number of rows.
Columns
Int
Number of columns.
Event Handlers:
Event Name
Description
OnSelectionChanged
Name of protected method that is implemented inside the code behind and which will be called after selection is changed.
Methods:
Method Name
Parameter Type
Description
SelectAll
void
Make selection on all friends visible in the control - if list of friends are filtered, only filtered friends are selected.
UnselectAll
void
Unselect all friends.
FilterByNameStartsWith
String
Filter friends to only those whose name starts with provided parameter.
FilterByNameContains
String
Filter friends to only those whose name contains provided parameter as sub string.
GetSelectedFriends
void
Get list of selected friends. Method will return IList of FriendData objects.
Usage Examples:
Following examples show registration and insertion of Select Facebook Friends ASP.NET control in ASPX file. In the code behind, you can see usage of methods for selection, filtering, getting selected friends, and implementation of an event handler in C# and VB.NET programming languages.
ASPX Integration: <%@ Page MasterPageFile="~/Components2Master.Master" AutoEventWireup="true" Inherits="FVK_Demo.SelectFriends" %> <%@ Register TagPrefix="fvk" TagName="selectfriends" Src="~/FVK/SelectFriends.ascx" %> <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder2" runat="server"> <fvk:selectfriends id="selectfriends1" runat="server" OnSelectionChanged = "OnSelectedFriends" Rows = "4" Columns = "3" /> </asp:Content> Code behind 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.Web;
using FVK;
namespace FVK_Demo
{
public partial class SelectFriends : Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
// get facebook friends whose names starts with 'a'
selectfriends1.FilterByNameStartsWith("a");
// get facebook friends whose names cantains 'b' character
selectfriends1.FilterByNameContains("b");
// select all filtered friends
selectfriends1.SelectAll();
// unselect all filtered friends
selectfriends1.UnselectAll();
}
}
protected void OnSelectedFriends(object sender, EventArgs e)
{
IList
Code behind in VB.NET:
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports Facebook.Web
Imports FVK
Namespace FVK_Demo
Public Partial Class SelectFriends
Inherits Page
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
' get facebook friends whose names starts with 'a'
selectfriends1.FilterByNameStartsWith("a")
' get facebook friends whose names cantains 'b' character
selectfriends1.FilterByNameContains("b")
' select all filtered friends
selectfriends1.SelectAll()
' unselect all filtered friends
selectfriends1.UnselectAll()
End If
End Sub
Protected Sub OnSelectedFriends(sender As Object, e As EventArgs)
Dim selectedFriends As IList(Of FriendData) = selectfriends1.GetSelectedFriends()
' do something on change of selection
End Sub
End Class
End Namespace
|