2012-03-14 22 views
2

約20の製品一覧を表示するASP.NET 4.0ホームページがあります。各商品リストには、次の形式のURLが表示されます。/DisplayProduct.aspx?ProdID=XASP.NETユーザーコントロールのGoogle Plus

各商品リストの前にGoogleプラスとリツイートの数が表示されます。どのようにして最適な方法で最適化し、ページの読み込み速度に影響を与えずに行えますか?どのようなスクリプトを使用する必要がありますか?

ここでは、上記のは、あなたがその製品を指す別のURLで、製品ごとに繰り返して欲しいものであること

<!-- 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> 

ような何かをしなければならないコード

<%@ 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> 

答えて

1

とユーザーコントロールのページ。

以下のスクリプトを繰り返してはいけません。

<!-- 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> 

希望します。

+0

このスクリプトをユーザーコントロールに追加する必要がありますか?それはどこに合うのですか?さらに、製品のURLは動的に作成されています。したがって、> g:plusoneスクリプトで指定することはできます – CuriousDev

+0

リンクにNavigateUrlを設定するのと同じ方法でhrefを割り当てる必要があります。 –

+0

g +ボタンが他の場所にある場合は、このスクリプトをページの最下部に置いておきます。このスクリプトは、ページの下部に配置するのが理想的です(ブラウザはコンテンツを最初に表示してからスクリプトに注意してください)。 –

関連する問題