UpdatePanel和Timer使用问题

yaojiangwei315 2010-05-11 12:53:13
aspx文件:
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="TimerForNew" runat="server" Interval="5000"
OnTick="TimerForNew_Tick" Enabled="true">
</asp:Timer>
<div style="text-align:center;"><h2>照片传回实时监测</h2></div>
<div style="text-align:center;">
<asp:DataGrid ID="dlNews" runat="server" AutoGenerateColumns="False"
BorderColor="#0E7C6E" BorderWidth="1px" CellPadding="3" Font-Size="12px" Width="92%" >
<SelectedItemStyle CssClass="DataGrid-selected"/>
<AlternatingItemStyle CssClass="DataGrid-alter" HorizontalAlign="Center" VerticalAlign="Middle" />
<ItemStyle CssClass="DataGrid-item" HorizontalAlign="Center" VerticalAlign="Middle" />
<HeaderStyle CssClass="DataGrid-header" HorizontalAlign="Center" VerticalAlign="Middle" />
<Columns>
<asp:BoundColumn DataField="orderID" HeaderText="序号" >
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="6%"/>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundColumn>
<asp:BoundColumn DataField="cCmpName" HeaderText="公司名">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="14%"/>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundColumn>
<asp:BoundColumn DataField="cCarNum" HeaderText="车牌号">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="10%"/>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundColumn>
<asp:BoundColumn DataField="cTelNum" HeaderText="终端号">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="12%"/>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundColumn>

<asp:BoundColumn DataField="cftrName" HeaderText="站 点">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="12%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="cOpType" HeaderText="拍照类型">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="8%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="dOpTime" HeaderText="拍照时间">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="16%"></HeaderStyle>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle>
</asp:BoundColumn>

<asp:BoundColumn DataField="cPhotoPath" HeaderText="照片名称" Visible="false">
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="18%"/>
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
</div>
</ContentTemplate>
</asp:UpdatePanel>
</div>



cs文件:

protected void TimerForNew_Tick(object sender, EventArgs e)
{
//if (flag == 1)
//{
// Label1.Text = "1变化";
// flag = 2;
//}
//else
//{
// Label1.Text = "2变化";
// flag = 1;
//}
newNum = Int32.Parse(BLL.Report.GetAllInfo().Rows[0]["cID"].ToString());
DataTable table = new DataTable();
if (newNum > num || isClear)
{
table = BLL.Report.GetNewPho(num + 1, newNum);
//table = BLL.Report.GetNewPho(num, newNum);
table.Columns.Add(new DataColumn("orderID", typeof(string)));
table.Columns.Add(new DataColumn("cCmpName", typeof(string)));
for (int i = 0; i < table.Rows.Count; i++)
{
table.Rows[i]["orderID"] = i + 1;
table.Rows[i]["cCmpName"] = BLL.Company.GetCompanyTable(table.Rows[i]["cTelNum"].ToString().Substring(0, 4)).Rows[0]["cCmpName"].ToString();
}
dlNews.DataSource = table.DefaultView;
dlNews.DataBind();
isClear = false;
}
}

现在程序不能进入到TimerForNew_Tick方法,定时器不知道为什么不可用,请帮帮忙
...全文
213 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
yaojiangwei315 2010-05-11
  • 打赏
  • 举报
回复
是的,而且一直报Error:Sys.WebForms.PageRequestManagerTimeoutException: 服务器请求超时。
这种错
koukoujiayi 2010-05-11
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 yaojiangwei315 的回复:]
找到原因了,EnablePartialRendering="False"这样就可以了
[/Quote]
那就不能异步回发了!!
yaojiangwei315 2010-05-11
  • 打赏
  • 举报
回复
找到原因了,EnablePartialRendering="False"这样就可以了
yaojiangwei315 2010-05-11
  • 打赏
  • 举报
回复
确实触发了,一开始不知道为什么没有触发。
<tr>
<td><asp:Button ID="btnClear" runat="server" Text="清 除" CssClass="buttonCss" OnClick="btnClear_Click" Height="20px" /></td><td>
<asp:Button ID="btnSave" runat="server" Text="保 存" CssClass="buttonCss" OnClick="btnSave_Click" Height="20px" /></td><td>
<asp:Button ID="btnGet" runat="server" Text="提 取" CssClass="buttonCss" OnClick="btnGet_Click" Height="20px" /></td><td>
<asp:Label ID="lblTime" runat="server" Text="Label" Visible="false"></asp:Label></td>
</tr>

我在cs文件if后面加上
else
{
lblTime.Visible = true;
lblTime.Text = "没有传回图片";
}
最终lblTime没有显示出来,也调用到else里面了。
koukoujiayi 2010-05-11
  • 打赏
  • 举报
回复
楼主的代码看不出有什么错!!
可能系统有问题!
做个简单的测试一下,Timer的事件是否触发!!
语句少一点,如下:
  <asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Timer ID="TimerForNew" runat="server" Interval="2000" OnTick="TimerForNew_Tick" Enabled="true">
</asp:Timer>
</ContentTemplate>
</asp:UpdatePanel>
yaojiangwei315 2010-05-11
  • 打赏
  • 举报
回复
没有触发
皇城龙三 2010-05-11
  • 打赏
  • 举报
回复
跟踪一下TimerForNew_Tick,里面的内容,看看有没有触发
JustDoIt_NotLast 2010-05-11
  • 打赏
  • 举报
回复
占位学习

17,742

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 .NET Framework
社区管理员
  • .NET Framework社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧