Thursday, May 3, 2012

Adding Facebook Share Functionality to an ASP.NET Website

Adding Facebook Share Functionality to an ASP.NET Website
<html xmlns="http://www.w3.org/1999/xhtml" >

<head id="Head1" runat="server">
    <title>Facebook share sampel</title>
    <script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"
           type="text/javascript">
</script>
</head>

<body>

<form id="Form1" runat="server">

<div>

 <a name="sharebutton" type="button" href="http://www.facebook.com/sharer.php">Share</a>
    <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

</div>

</form>

</body>

</html>





Aspx.cs



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Sharefacebook : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Label1.Text = "<a name=\"fb_share\" type=\"button\"></a>" +
"<script " +
"src=\"http://static.ak.fbcdn.net/connect.php/js/FB.Share\" " +
"type=\"text/javascript\"></script>";
HtmlMeta tag = new HtmlMeta();
tag.Name = "title";
tag.Content = "This is the page title";
Page.Header.Controls.Add(tag);
HtmlMeta tag1 = new HtmlMeta();
tag.Name = "description";
tag.Content = "This is a page description.";
Page.Header.Controls.Add(tag1);
}
} 

OR
 
 
using System;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Net.Mail;

namespace MHT_Web_Site
{
public partial class MyPage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
try
{
labelSteps_1_2.Text = "<a name=\"fb_share\" type=\"button\"></a>" +
"<script " +
"src=\"http://static.ak.fbcdn.net/connect.php/js/FB.Share\" " +
"type=\"text/javascript\"></script>";

HtmlMeta tag = new HtmlMeta();
tag.Name = "title";
tag.Content = “This is the Title”;
Page.Header.Controls.Add(tag);

HtmlMeta tag = new HtmlMeta();
tag.Name = "description";
tag.Content = “This is a short summary of the page.”;
Page.Header.Controls.Add(tag);

HtmlLink link = new HtmlLink();
link.Href = “http://www.murrayhilltech.com/images/LogoColorNoText.jpg”;
link.Attributes["rel"] = "image_src";
Page.Header.Controls.Add(link);

}
catch (Exception ex)
{
// Handle the exception
}
}
}
}

No comments:

Post a Comment