我有一个更新面板,用于更新网格视图,该网格视图连接到mySql数据源,并且更新面板的触发器是一个每1秒滴答一次的计时器。
,但是问题是当计时器计时时,整个页面都会回发。 有什么主意吗?
<asp:ScriptManager ID="ScriptManager1" OnLoad="Timer1_Tick" runat="server" />
<asp:UpdatePanel ID="UpdatePanel1" UpdateMode="Conditional" ChildrenAsTriggers="true" runat="server">
<ContentTemplate>
<asp:Timer ID="Timer1" runat="server" Interval="1000" OnTick="Timer1_Tick" Enabled="False">
</asp:Timer>
<asp:GridView ID="GridView3" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource3">
<Columns>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Sensor1" HeaderText="Sensor1" SortExpression="Sensor1" />
<asp:BoundField DataField="Sensor2" HeaderText="Sensor2" SortExpression="Sensor2" />
<asp:BoundField DataField="Sensor3" HeaderText="Sensor3" SortExpression="Sensor3" />
<asp:BoundField DataField="Sensor4" HeaderText="Sensor4" SortExpression="Sensor4" />
<asp:BoundField DataField="Time" HeaderText="Time" SortExpression="Time" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:MyDatabaseConnectionString %>" SelectCommand="SELECT * FROM [Customer]" OnSelecting="SqlDataSource3_Selecting"></asp:SqlDataSource>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="Timer1" />
</Triggers>
</asp:UpdatePanel>
计时器后面的代码是:
protected void Timer1_Tick(object sender, EventArgs e)
{
GridView3.DataBind();
}
答案 0 :(得分:0)
我像下面的代码一样更改了触发标签,它起作用了:)
<Triggers>
<asp:AsyncPostBackTrigger ControlID="Timer1" />
</Triggers>