为什么asp:UpdatePanel不刷新图像?
问题描述:
我有以下的UpdatePanel从ashx处理程序获取图像,当页面刷新时,所有这些都可以正常工作。但是,当定时器启动时,标签会随着当前时间刷新,但不会显示图像。为什么asp:UpdatePanel不刷新图像?
<asp:UpdatePanel runat="server" id="TimedPanel" UpdateMode="Conditional">
<ContentTemplate>
<asp:Image ID="Image1" runat="server" Height="218px"
ImageUrl="~/getImage.ashx?cam=1" Width="303px" BorderWidth="10px" />
<asp:Timer ID="UpdateTimer" runat="server" interval="1250"
ontick="UpdateTimer_Tick" />
<asp:Label ID="DateStampLabel" runat="server" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger controlid="UpdateTimer" eventname="Tick" />
</Triggers>
</asp:UpdatePanel>
计时器例程是:
protected void UpdateTimer_Tick(object sender, EventArgs e)
{
DateStampLabel.Text = DateTime.Now.ToString();
}
为什么不是图像刷新?
答
AJAX通常很容易浏览器缓存。我通常在URL中添加一个DateTime.Now.Ticks
。此外,您的UpdateMode是有条件的,您必须致电Update()
:
protected void UpdateTimer_Tick(object sender, EventArgs e)
{
DateStampLabel.Text = DateTime.Now.ToString();
Image1.ImageUrl += "&CacheBuster=" + DateTime.Now.Ticks.ToString();
TimedPanel.Update();
}
感谢您的建议...我做了更改,但仍然没有更新。我修改了你的建议,以便ImageUrl不会变得非常大:Image1.ImageUrl =“〜/ getImage.ashx?cam = 2&CacheBuster =”+ DateTime.Now.Ticks.ToString(); ...其他建议? – Dave31836
似乎现在正在工作...... ashx中的某些东西引起了异常,并且似乎禁用了进一步的刷新。 – Dave31836