计时器计时时,TextBox失去焦点



我在页面的特定部分放置了一个计时器控件,但每次计时器计时时,我在另一部分的文本框(我有多个文本框)就会失去焦点。

我该如何解决此问题?我试着把计时器放在一个单独的更新面板里。计时器Tick事件中的代码是

 protected void Timer1_Tick(object sender, EventArgs e)
    {
        if ((List<AllPostInformation>)Session["AllNewsPostCollection"] != (List<AllPostInformation>)Session["CheckExistData"])
        {
            if ((List<AllPostInformation>)Session["AllNewsPostCollection"] != null)
            {

                List<AllPostInformation> o = new List<AllPostInformation>();
                o = (List<AllPostInformation>)Session["AllNewsPostCollection"];
                rptNews.DataSource = o;
                rptNews.DataBind();
            }
            Session["CheckExistData"] = Session["AllNewsPostCollection"];
        }
    }

和asp页面

 <asp:UpdatePanel runat="server" ID="upTimer">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
        </Triggers>
        <ContentTemplate>
            <asp:Timer ID="Timer1" runat="server" Interval="5000" />
        </ContentTemplate>
    </asp:UpdatePanel>

如果你看看这个链接中的帖子,Focus在UpdatePanel中丢失了部分回发UserControls,你会发现你不需要把计时器控件放在更新面板中,而是放要更新的项目。

最新更新