我有一个页面,它从远程服务中检索字符信息,然后在UpdatePanel内的表中显示信息。如果我所做的只是向表中添加tablerows,tablecells和text,那么表格会完全刷新。但是,如果我尝试通过img标签或Image类添加图像,表格会更新一次,然后再拒绝更新。
我已经完成了一些谷歌搜索,并在每次搜索时阅读了前几页的结果,并检查了堆栈溢出,并且没有任何结果符合我的具体问题。我可以没有图像,但理想情况下,我想添加它们,因为我想用它们直观地表示当前影响每个游戏角色的状态效果。代码如下。
<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
数组中的可能值数量有限(我只是假设它们与字符名称相关联),您可以设置多个类,每个类都指向一个特定的图像网址,并根据方法的参数分配所需的任何一个。