Facebook在ListView中 [英] facebook like in ListView

查看:65
本文介绍了Facebook在ListView中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为datalist中的每个产品都设置按钮,我做了这些



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")%>'' />





但最后他们会引用mywebsite.com,当我喜欢其中一个时,他们都喜欢。



请帮助我非常需要。



- -------------------------------------------------- -----

------------------------------------- --------------------



Update 5/11/2013



我明白如果没有Meta Data这是不可能完成这项任务的,所以我提供了下面的代码来解决我的大部分问题,但是这会增加新的。



我的Index.aspx页面



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>







我的Like.aspx代码隐藏




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);
            }
        }
    }
}





问题是即使是在元数据中设置url url保持Like.aspx?ID =数字。

另外,我试图在index4.aspx中设置元数据,但它有其他问题。

有任何想法吗?

i将非常感谢你的帮助,谢谢你。



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.

推荐答案

好的...我不知道你如何实现你的喜欢代码隐藏但是从URL我可以猜到问题。



在这个片段中:

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>





您可以将每个人都称为动态生成的页面,即根据URL参数m中存在的数据动态生成的页面。所以事实上你所有的喜欢都被引导到页面''http://mywebsite.com/index.aspx'',因为facebook没有解析网址中解析的参数。这恰好是主页(来自名称index.aspx的猜测)。喜欢静态页面(喜欢我喜欢的)。



我的建议是使用这样的URL



http://mywebsite.com/product或http://mywebsite.com/id

这将允许您正确使用类似功能。 (这个概念来自wordpress,如伪静态页面)



为此,您可能需要在指定节点重构根和/或服务器应用程序(产品)或id)。



祝你好运!



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!


这篇关于Facebook在ListView中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆