2013-01-13 65 views
4

我有一個頁面,它從遠程服務中檢索字符信息,然後將信息顯示在UpdatePanel中的表格中。如果我所做的只是將表格,表格和文本添加到表格中,表格會更新得很好。但是,如果我嘗試通過img標記或Image類添加圖像,表會更新一次,然後拒絕更新。ASP.NET/Timer/Table + Image = No Tick/update

我已經經歷了幾次Google搜索,並在每次搜索中通讀了第一對夫婦頁面的結果,以及檢查計算器,並且沒有任何結果符合我的具體問題。我可以不使用圖像,但理想情況下,我想添加它們,因爲我想用它們來直觀地表示當前影響每個遊戲角色的狀態效果。代碼如下。

<asp:ScriptManager ID="scMain" runat="server" /> 
<asp:Timer ID="tmrRefresh" runat="server" Interval="5000" Enabled="true" /> 
<asp:UpdatePanel ID="udPanel" runat="server"> 
<Triggers> 
    <asp:AsyncPostBackTrigger ControlID="tmrRefresh" EventName="Tick" /> 
</Triggers> 
<ContentTemplate> 
    <asp:Table id="tblCharacters" runat="server"> 
     <asp:TableHeaderRow> 
      <asp:TableHeaderCell>Focus</asp:TableHeaderCell> 
      <asp:TableHeaderCell>Character</asp:TableHeaderCell> 
      <asp:TableHeaderCell>Location</asp:TableHeaderCell> 
      <asp:TableHeaderCell>Ping</asp:TableHeaderCell> 
     </asp:TableHeaderRow> 
    </asp:Table><br /> 
    <asp:Label ID="lblNote" runat="server" /> 
</ContentTemplate> 
</asp:UpdatePanel> 

代碼隱藏:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
    If Not Master.IsLoggedIn Then 
     Response.Redirect("login.aspx") 
    Else 
     FillCharacterTable() 
    End If 
End Sub 

Private Sub FillCharacterTable() 
    Dim Foci() As Byte = {0, 4, 10, 19, 24} 
    Dim Names() As String = {"Unknown", "Gatekeeper", "Dreamseer", "Soulmaster", "Fatesender"} 
    Dim HaloColors() As Byte = {0, 4, 15, 7, 18} 

    Dim c As New CharacterInfoClient ' Remote service 

    Dim Characters() As String = c.GetCharacterInformation 

    For Each s As String In Characters 
     Dim args() As String = s.Split("|") 
     Dim tr As New TableRow 
     ' add focus elemen icon 
     Dim focus As Byte = Foci(args(2)) 

     ' option 1 - causes timer to stop updating 
     tr.Cells.Add(New TableCell With {.Text = String.Format("<img src=""http://mydomainremoved.net/images/game/image.gif?s=7&v=3&c1={0}&c2={0}&st=50"">", focus))}) 

     ' Option 2, same thing 
     Dim tc As New TableCell 
     tc.Controls.Add(New Image With {.ImageUrl = String.Format("http://mydomainremoved.net/images/game/image.gif?s=7&v=3&c1={0}&c2={0}&st=50", focus)}) 

     tr.Cells.Add(tc) 

     tr.Cells.Add(New TableCell With {.Text = "<a href=""character.aspx?id=" & args(1) & """>" & args(0) & "</a>"}) 
     tr.Cells.Add(New TableCell With {.Text = args(4)}) 
     tr.Cells.Add(New TableCell With {.Text = args(7)}) 

     tblCharacters.Rows.Add(tr) 
    Next 

    lblNote.Text = Characters.Length & " characters -- " & Now.ToString 

End Sub 
+0

應該是圖像的大小? –

回答

0

也許這將有一個CSS類,而不是一個圖像標記實驗是值得?

td.gatekeeper 
{ 
    background-image: url('http://mydomainremoved.net/images/game/image.gif?s=7&v=3&c1=10&c2=10&st=50'); 
} 
td.dreamseer 
{ 
    // etc. 
} 

既然你有你的Foci陣列可能值的數量有限(我只是假設他們綁在角色的名字),你可以設置多個類,每一個點到一個特定的圖像網址,並根據方法的參數分配需要的。