Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET HTML Facebook
i am trying to have like button for every product in datalist, and i did these
 
    <fvk:likebutton ID="Likebutton3"  runat="server" Url=' <%# "http://mywebsite.com/index.aspx#"+DataBinder.Eval(Container.DataItem, "ID")%>' />
 
    <fvk:likebutton ID="Likebutton3"  runat="server" Url=' <%# "http://mywebsite.com/index.aspx?m="+DataBinder.Eval(Container.DataItem, "ID")%>' />
 
but finally they refer to mywebsite.com, and when i like one of them all liked.
 
Please help i need this badly.
 
--------------------------------------------------------
---------------------------------------------------------
 
Update 5/11/2013
 
I understood that it is impossible do this task without Meta Data, so i provided below code which solve most part of my problems, but that rise new one.
 
My Index.aspx page
<%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="index4.aspx.cs" Inherits="Winner.index4" %>
<%@ Register TagPrefix="fvk" TagName="subscribe" Src="~/FVK/SubscribeToEvent.ascx" %>
<%@ Register TagPrefix="fvk" TagName="likebutton" Src="~/FVK/LikeButton.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link href="MyStyle/index.css" rel="stylesheet" />
      <script type="text/javascript" src="Scripts/jquery-1.9.1.min.js"></script>
   
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
      <asp:UpdatePanel ID="PublishLabelUpdatePanel" runat="server">
           <ContentTemplate>
       <fvk:subscribe ID="subscribe1" EventName="Like"  runat="server"  önEventTrigger="OnLike" />
       <fvk:subscribe ID="subscribe2" EventName="Unlike"  runat="server"  önEventTrigger="OnUnlike" />
         <div style="padding:3px;padding-removed24px;padding-removed6px">
                <asp:Label ID="EventLabel" runat="server" ForeColor="Green"></asp:Label>
    
                <br />
         </div>
               </ContentTemplate>
        </asp:UpdatePanel>
    <div id="holder" class="div_listview">
      <asp:DataList ID="DataList1" CssClass="DataListCoundown" runat="server">
        <ItemTemplate>
            <div class="divlistitem">
   
   
             <asp:Image ID="Image1" runat="server"  ImageUrl='<%#"GetImage.aspx?id="+Eval("IDproduct") %>'  Width="400px"/>
 

   
            <br />
      <fvk:likebutton ID="Likebutton3"  runat="server" Send="true"  Url='<%#"http://www.mywebsite.com/Like.aspx?ID=" + Eval("ID")%>' Width="400" />
 
           </div>              
                 </ItemTemplate>
    </asp:DataList>
        </div>
   
</asp:Content>
 

My Like.aspx codebehind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
 
namespace Winner
{
    public partial class like : System.Web.UI.Page
    {
        class show
        {
            public long ID { get; set; }
            public long IDproduct { get; set; }
            public string Name { get; set; }
            public byte[] Image { get; set; }
            public DateTime Time_end { get; set; }
            public int Seconds { get; set; }
 

 
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                // Get the product meta content from the ID URL parameter.
                string productName = "";
                string productImageURL = "";
                string productDescription = "";
                int ShowID = 0;
                if (Request.QueryString["ID"] != null)
                {
                    //productID = Convert.ToInt32(Request.QueryString["ID"]);
                    ShowID = Convert.ToInt32(Request.QueryString["ID"]);
                }
                if (Request.QueryString["ID"] != null)
                {
 
                   
 
                    DBCardEntities context = new DBCardEntities();
 
                  
 
                    List<show> showList = new List<show>();
                    var ListShow = (from s in context.LikeShows
                                    join p in context.Products on s.Product_ID equals p.ID
                                    where s.ID == ShowID
                                    select new { s.ID, p.Description, p.Name, p.Image, s.Time_End, s.Time_Start, productId = p.ID }).FirstOrDefault();
 
                    ShowID = Convert.ToInt32(Request.QueryString["ID"]);
                    productName = ListShow.Name;
                    productImageURL = "GetImage.aspx?id=" + ListShow.productId.ToString();
                    productDescription = ListShow.Description;
                }
 
                // Dynamically generate Open Graph Meta Tags for each Product:
                HtmlMeta _metaTitle = new HtmlMeta();
                _metaTitle.Name = "og:title";
                _metaTitle.Content = "Product: " + productName;
                this.Header.Controls.Add(_metaTitle);
 
                HtmlMeta _metaURL = new HtmlMeta();
                _metaURL.Name = "og:url";
                _metaURL.Content = "http://piraly.cnsuite.com/index4.aspx?ID=" + Convert.ToString(ShowID);
                this.Header.Controls.Add(_metaURL);
 
                HtmlMeta _metaImage = new HtmlMeta();
                _metaImage.Name = "og:image";
                _metaImage.Content = Convert.ToString(productImageURL);
                this.Header.Controls.Add(_metaImage);
 
                HtmlMeta _metaDescription = new HtmlMeta();
                _metaDescription.Name = "og:description";
                _metaDescription.Content = Convert.ToString(productDescription);
                this.Header.Controls.Add(_metaDescription);
            }
        }
    }
}
 
and the problem is that even by setting the url in metadata the url stays Like.aspx?ID=a number.
Also, i tried to set the metadata in index4.aspx but it had other problems.
Do have any idea ?
i will appreciate your help thank you.
Posted 30-Apr-13 17:01pm
Edited 11-May-13 14:24pm
v4
Comments
Sandeep Mewara at 1-May-13 0:43am
   
I doubt if that would be the only code related to pass on the like information. Like one and all is liked does not looks like happening in above code.
Christ_88 at 1-May-13 0:46am
   
i know that must not happen, but when i use <%# %> that transform my all likes url to www.mywebsite.com
Member 8371841 at 1-May-13 4:20am
   
Facebook likes are site-specific. I doubt if they have a page specific like
Christ_88 at 1-May-13 13:28pm
   
thank you for your responses, i am sure Facebook has page specific like
Christ_88 at 1-May-13 13:30pm
   
http://hillarsaare.com/projects/facebook/multi-like/
see this demo, but i dont know how can i make it for datalist likes.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Ok... I donno how you implement likes in your code-behind but from the URL I can guess the problem.
 
In this snippet :
<fvk:likebutton id="Likebutton3" runat="server" url=" <%# "http://mywebsite.com/index.aspx?m="+DataBinder.Eval(Container.DataItem, "ID")%>" xmlns:fvk="#unknown">
</fvk:likebutton>
 
You refer every like to a "dynamically generated page" i.e., one generated on the fly according to the data present in the URL parameter 'm'. So in fact all your likes are directed to the page 'http://mywebsite.com/index.aspx' as facebook doesn't parse the parameters parsed in the urls. This happens to be the home page (a guess from the name index.aspx). Likes are possible for static pages (as of my understanding of likes).
 
My suggestion is to use an URL like this
 
http://mywebsite.com/product or http://mywebsite.com/id
This will allow you to use the like feature properly. (This concept was borrowed from wordpress like "pseudo-static" pages)
 
For this you may have to restructure the root and/or server application at specified node (product or id).
 
Good luck!
  Permalink  
Comments
Christ_88 at 1-May-13 13:27pm
   
but i guess something is wrong with <%%> (binding) because when i change the url to
Url="http://www.piraly.cnsuite.com/index.aspx?ID=1" <-- in datalist
facebook embed the like to the link, and even when i have
Url="http://www.piraly.cnsuite.com/index.aspx?ID=1"
Url="http://www.piraly.cnsuite.com/index.aspx?ID=2"
Url="http://www.piraly.cnsuite.com/index.aspx?ID=3" <---- out of datalist
 
it can easily differentiate, but when i try to bind the text it break.
even i tried to embed the same binding to a Lable, and that was completely fine. i dont now how can i debug it, do you have any idea?
Thank you for your response.
Member 8371841 at 1-May-13 22:11pm
   
Couldn't get u?? Can u explain what you wanna say by "Url... <-- out of data list"
Do you wanna say that fb embeds likes for pages that is non-existent??
Member 8371841 at 1-May-13 22:49pm
   
In the solution it speaks about some meta tags... in the pages you mentioned I couldn't find any
Try adding and see:
 
<meta property="og:title" content="TITLE"/>
<meta property="og:url" content="http://yoururlhere"/>
<meta property="og:image" content="ABSOLUTE_IMAGE_URL"/>
<meta property="og:description" content="DESCRIPTION"/>
<meta property="og:site_name" content="YOUR_SITE'S_NAME"/>
<meta property="og:type" content="product"/>
<meta property="fb:app_id" content="APP_ID"/>
 
A trick: Since you use asp pages the og:url tag content MUST BE THE URL DISPLAYED IN BROWSER FOR BEST RESULTS i.e., http://mysite.com/product.php?id=23134
 
I'm not that geek in ASP but i'm sure it has a method to get the url.
Christ_88 at 2-May-13 16:39pm
   
Can u explain what you wanna say by "Url... <-- out of data list"
I mean the like which i put out of data list and i did not embed their url, and i just wrote them. ye your are right i didnt use the solution because when i wrote the url with ?m=1 it didnt have any problem.
Christ_88 at 2-May-13 21:23pm
   
this one work fine
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<fvk:likebutton ID="Likebutton2" runat="server" Url="http://mywebsite.com/test.aspx?m=1" />
<fvk:likebutton ID="Likebutton1" runat="server" Url="http://mywebsite.com/test.aspx?m=2" />
<fvk:likebutton ID="Likebutton3" runat="server" Url="http://mywebsite.com/test.aspx?m=3" />
Amitosh Swain at 3-May-13 3:15am
   
Please provide some more code to dig in...
I also suspect the same... problem with binding
make a small test by inserting a small html tag in place of the something like

<%# "http://mywebsite.com/index.aspx?m="+DataBinder.Eval(Container.DataItem, "ID")%>"

and note what's displayed

 
Here is some more detail about dataitem Databinder.eval
Christ_88 at 12-May-13 20:09pm
   
i updated the question could u have look ?
Amitosh Swain at 12-May-13 20:52pm
   
hmmmm.... I don't see the possibility of a url like that! It's strange.
Ok. Do ypu host in somewhere for testing. If yes then plz give a link to preview in browser
Christ_88 at 12-May-13 23:57pm
   
actually i can not show my problem on server for you. lets explain in this way and if you did not get it i will upload it.
right know when some one like my product it works perfect but when another person click the person liked link and come to my web site, the second person has a completely different like link because Facebook generate some QueryString on my link and the QueryStrings change my like URL and that continuous.
 
but i set the url in meta data then why it changes the like url ?
 
if it is not obvious, let me know to upload it on a server.
Amitosh Swain at 13-May-13 20:41pm
   
ok ok. But it will be a bit harder to debug. Then check whether the GENERATED CODE (the html that's actually sent to the browser) has a proper , tag. It must include an href="http://some_url_which_has_meta_tags" attribute. Sometimes when there is no href tag, Fb redirects the like to somewhere else... If this is the problem then, check your LikeButton.ascx for possible errors.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 545
1 OriginalGriff 285
2 Shweta N Mishra 244
3 BillWoodruff 230
4 Mathew Soji 225
0 OriginalGriff 6,153
1 Sergey Alexandrovich Kryukov 5,758
2 DamithSL 4,958
3 Manas Bhardwaj 4,539
4 Maciej Los 3,735


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 11 May 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100