ASP timer Control is refreshing the whole page?

2019-03-02 18:15发布

问题:

I have a ASP timer control which is supposed to run every three minutes. Although I kept the Timer control in an update panel, it is refreshing the whole page every time it runs.

Is there any it only refresh the particular section of the page, not the whole page?

<div>
        <asp:UpdatePanel ID="UpdatePanel4" runat="server">
            <ContentTemplate>
                <asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick" Interval="300000" >
                </asp:Timer>
            </ContentTemplate>
        </asp:UpdatePanel>               
    </div>

回答1:

        <asp:Timer runat="server" id="UpdateTimer" interval="200" ontick="function" />

        <asp:UpdatePanel runat="server" id="TimedPanel" updatemode="Conditional">

            <Triggers>
                <asp:AsyncPostBackTrigger controlid="UpdateTimer" eventname="Tick" />
            </Triggers>

            <ContentTemplate>
                <asp:Label runat="server" id="label1" />
                <asp:TextBox ID="textbox1" runat="server"></asp:TextBox>
            </ContentTemplate>

        </asp:UpdatePanel>     


回答2:

 <asp:UpdatePanel ID="UpdatePanel4" runat="server">
   <Triggers>
    <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
  </Triggers>
  <ContentTemplate>
   <asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick" Interval="300000"></asp:Timer>
            </ContentTemplate>
        </asp:UpdatePanel> 


回答3:

you need to use UpdatePanel Triggers. Conditional Update Panels with triggers, and msdn source. Updatepanel with Triggers

   <asp:UpdatePanel ID="UpdatePanel4" runat="server">
       <ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
    </Triggers>
<asp:Timer ID="Timer1" runat="server" ontick="Timer1_Tick" Interval="300000"> </asp:Timer>
                </ContentTemplate>
            </asp:UpdatePanel> 


回答4:

Use update panel and add all the control's inside update panel which you don't want to be refreshed or postback by any event