2011-09-12 14 views
0

我在我的網頁上使用餅圖,必須每4秒更新一次,所以我使用了這個如何僅刷新網站的幾個部分

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="Server"> 
    <meta http-equiv="refresh" content="4" /> 

我的餅圖位於頁面底部。每次頁面刷新時頁面都會顯示在頂部。當我向下滾動以查看餅圖時,它會再次刷新。

 //Passing values to draw pie chart 

    var pie1 = new RGraph.Pie('pie1', <%= Session["uStats"] %>); 
// Create the pie object 
      pie1.Set('chart.key', ['Read', 'Received', 'Not Received']); 
      pie1.Set('chart.key.align', 'right'); 
      pie1.Set('chart.key.position.x', 200); 
      pie1.Set('chart.key.position.y', 100); 
      //pie1.Set('chart.gutter.right', 100); 
      pie1.Set('chart.colors',['#86cf21', '#eaa600', '#e01600']); 
      pie1.Set('chart.title', "Message Status"); 
      pie1.Set('chart.align', 'left'); 
      pie1.Set('chart.shadow', true); 
      pie1.Set('chart.radius', 70); 
      pie1.Set('chart.labels.sticks', false); 
      pie1.Set('chart.tooltips.effect', 'fade'); 
      pie1.Set('chart.tooltips.event', 'onmousemove'); 
      pie1.Set('chart.highlight.style', '3d'); // Defaults to 3d anyway; can be 2d or 3d 


      if (!RGraph.isIE8()) 
      { 
       pie1.Set('chart.zoom.hdir', 'center'); 
       pie1.Set('chart.zoom.vdir', 'up'); 
       pie1.Set('chart.labels.sticks', false); 
       pie1.Set('chart.labels.sticks.color', '#aaa'); 
      } 
      pie1.Draw(); 
     } 
//I add the values to the session. 
Session.Add("uStats", "[" + read + "," + received2 + "," + NotReceived + "]"); 


<div id="pie" "top: 165px; left: 536px; width: 74px; position: absolute; height: 529px;"> 
     <canvas id="pie1" width="400" height="400">[No canvas support]</canvas>   
     </div> 

<asp:Panel runat="server" ID="Panel_Users" ScrollBars="Auto" Style="z-index: 1; left: 748px; 
       top: 621px; position: absolute; height: 250px; width: 287px"> 
       <asp:GridView ID="Grid_UserTable" runat="server" Style="z-index: 1; left: 2px; top: 5px; 
        position: absolute; height: 152px; width: 243px" BorderColor="#666666" AutoGenerateColumns="False" 
        OnRowDataBound="MyGrid_RowDataBound"> 
        <Columns> 
         <asp:TemplateField HeaderText="Status"> 
          <ItemTemplate> 
           <asp:Image ID="Status" runat="server" /> 
          </ItemTemplate> 
         </asp:TemplateField> 
         <asp:BoundField DataField="TimeReceived" HeaderText="TimeReceived" InsertVisible="False" 
          ReadOnly="True" SortExpression="TimeReceived" /> 
         <asp:BoundField DataField="TimeRead" HeaderText="TimeRead" SortExpression="TimeRead" /> 
         <asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" /> 
        </Columns> 
       </asp:GridView> 

     </asp:Panel> 

我必須更新表格和餅圖

什麼是解決方案,只刷新網站所需的部分,使網頁保持在準確的位置,而不是到頂部

+2

簡而言之,使用AJAX。 – Sorpigal

+0

你可以使用iFrame嗎? – JonH

回答

0

我需要知道更多關於您的設計的任何明確的說法,但您可以使用UpdatePanel以特定間隔更新您的圖表。只有UpdatePanel內部會更新。

這裏有一個如何更新內容每秒一個例子:

http://jquery-howto.blogspot.com/2009/04/ajax-update-content-every-x-seconds.html

+0

因此,每次更新面板得到更新時,服務器端代碼是否會被執行? – Mano

+0

是的,但您應該使用JavaScript調用以指定的時間間隔更新圖表,而不是元刷新。 –

5

什麼解決的辦法只有刷新所需零件

AJAX

toolsuse取決於你,但概念是相同的。基本上你需要的是頁面上的一些JavaScript,偶爾會向服務器資源發出請求以獲取更新的數據並更新頁面上的相關元素。

這是a simple example這是如何在瀏覽器中運行以及客戶端代碼和服務器端代碼如何交互。

0

通常,執行此操作的方法是編寫一個小頁面,該頁面可以輸出代表已更改部分的JSON片段或原始HTML。然後通過XMLHttpRequest定期從Javascript調用此頁面,捕獲其輸出,然後直接插入頁面以替換現有內容,或者如果使用JSON,則使用其值更新內容。

準確地說,如何做到這一點取決於你的情況,代碼庫,風格等。