Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
ASP.NET
<%@ 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
C#
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
Updated 11-May-13 13:24pm
v4
Comments
Sandeep Mewara 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 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
AlphaDeltaTheta 1-May-13 4:20am    
Facebook likes are site-specific. I doubt if they have a page specific like
Christ_88 1-May-13 13:28pm    
thank you for your responses, i am sure Facebook has page specific like
Christ_88 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

Ok... I donno how you implement likes in your code-behind but from the URL I can guess the problem.

In this snippet :
ASP.NET
<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!
 
Share this answer
 
Comments
Christ_88 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.
AlphaDeltaTheta 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??
AlphaDeltaTheta 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 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 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" />

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900