Tuesday, 4 September 2012

Add Share Button to Asp.net application


Drag and Drop a label inside of content place holder.
This label can drop any where in the page its totally depend on your choice.after that rename it as lblShare  and add the code at the page load event as given below.........
and Run your application ..........

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<asp:Label ID="lblShare" runat="server" Text=""></asp:Label>
</asp:Content>>

Code Behind.


using System.Web.UI.HtmlControls;
protected void Page_Load(object sender, EventArgs e)
{      
    lblShare.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);           
}


using this code you can share your page at Facebook. 

No comments:

Post a Comment