我有一个ASP.NET 4.0主页,显示大约20个产品列表。每个产品列表都会显示以下格式的网址:/DisplayProduct.aspx?ProdID=X
我想在每个商家信息页面前显示收到的每个商品详情的Google Plus和ReTweets数量。如何以最佳优化方式执行此操作,而不会过多地影响页面加载速度。必须使用哪些脚本?
这是带代码的用户控件
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ProductListing.ascx.cs" Inherits="Controls.ProductListing" %>
<asp:GridView ID="gvProducts" runat="server" AllowPaging="True" AutoGenerateColumns="False"
DataKeyNames="ID" DataSourceID="objProds" PageSize="10" ShowHeader="False"
OnRowDataBound="gvProducts_RowDataBound" OnRowCommand="gvProducts_RowCommand"
>
<Columns>
<asp:TemplateField HeaderText="Product List">
<HeaderStyle />
<ItemTemplate>
<div class="plist">
<table cellpadding="0" cellspacing="0" style="width: 100%;">
<tr><td>
<div class="productname">
<asp:HyperLink runat="server" ID="hypName" Text='<%# Eval("Name") %>'
NavigateUrl='<%# "~/DisplayProduct.aspx?ID=" + Eval("ProdID") %>'/>
</div>
</td> </tr>
</table>
<div class="productdesc">
<b>Description: </b>
<asp:Literal runat="server" ID="lblDesc" Text='<%# Eval("Description") %>' />
</div>
</div>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
答案 0 :(得分:1)
你应该做那样的事情
<!-- Place this tag where you want the +1 button to render -->
<g:plusone size="small" annotation="none" href="http://www.yourwebsite.com/DisplayProduct.aspx?ProdID=<%# Eval("Name") %>"></g:plusone>
以上是您希望针对每个产品重复使用不同网址指向该产品页面的内容。
以下脚本不应重复。
<!-- Place this render call where appropriate -->
<script type="text/javascript">
(function() {
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
po.src = 'https://apis.google.com/js/plusone.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
})();
</script>
希望它有所帮助。