LearnFast.Ninja

Like button generator using C# code behind

In this tutorial you will have functions to help you generate Like button via C Sharp code behind. You can pass as parameters the URL you want to redirect and the iframe width. You also can choose which layout style to have.

Step 1: Add this FacebookHelper class to your project.

public static class FacebookHelper

{

    public static string Get_Like_Button_Iframe_Standard(string URL, string iFrame_Width)

    {

        return "<iframe src='//www.facebook.com/plugins/like.php?href=" + URL + "&amp;send=false&amp;layout=standard&amp;width=" + iFrame_Width + "&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font&amp;height=80' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:" + iFrame_Width + "px; height:80px;' allowTransparency='true'></iframe>";

    }

 

    public static string Get_Like_Button_Iframe_Standard(string iFrame_Width)

    {

        return Get_Like_Button_Iframe_Standard(HttpContext.Current.Request.Url.ToString().ToLower(), iFrame_Width);

    }

 

 

    public static string Get_Like_Button_Iframe_Count_Button(string URL, string iFrame_Width)

    {

        return "<iframe src='//www.facebook.com/plugins/like.php?href=" + URL + "&amp;send=false&amp;layout=button_count&amp;width=" + iFrame_Width + "&amp;show_faces=true&amp;action=like&amp;colorscheme=light&amp;font&amp;height=21' scrolling='no' frameborder='0' style='border:none; overflow:hidden; width:" + iFrame_Width + "px; height:21px;' allowTransparency='true'></iframe>";

    }

 

    public static string Get_Like_Button_Iframe_Count_Button(string iFrame_Width)

    {

        return Get_Like_Button_Iframe_Count_Button(HttpContext.Current.Request.Url.ToString().ToLower(), iFrame_Width);

    }

}


Step 2: In your page class add this public variable.
public string Like_Button_Iframe_Count_Button = "";

Step 3: Assign the iframe on Page_Load.
Like_Button_Iframe_Count_Button = FacebookHelper.Get_Like_Button_Iframe_Count_Button("80");

Step 4: Put the variable in you aspx page where you want the like button to br located
<%=Like_Button_Iframe_Count_Button%>

Result:

or


Tags

asp.net

facebookhelper facebook like like-button getlikebuttons