【问题标题】:Ajax timer, update panels and repeatersAjax 计时器、更新面板和中继器
【发布时间】:2013-02-28 14:11:34
【问题描述】:

我在使用带有中继器的页面上的计时器时遇到问题。
我的页面基本上是这样的:(没有写下所有的标签和其他不重要的东西,页面很大)

<asp:Timer runat="server" Interval="5000" OnTick="UpdateTimer_Tick" ID="UpdateTimer" />
<UpdatePanel 1>
<dropdownlist/>
<Panel 1>
    <TextBox/><Button/>
</Panel 1>

<Repeater 1> //Bound to a list in code behind
    <Checkbox/><textbox/>
</Repeater 1>
<Button/>

<Repeater 2> //Bound to a list in code behind
    <button/><button/>
</Repeater 2>

<Repeater 3> //Bound to a dataset in code behind
    <textbox/><button/><button/>
</Repeater 3>
<button/><button/><button/>
</UpdatePanel 1>
<panel 2>
   //Jscript stuff that doesn't change anything to my current problem.
</panel 2>
<UpdatePanel 2>
    <Image/>
</UpdatePanel 2>

在我的页面中,我正在尝试添加一个 5000 毫秒滴答的计时器。 OnTick 事件需要调用我的 BindRepeater2 方法,因为我只想重新加载转发器以显示更新的信息。
我尝试将计时器放置在 updatePanel 之前、内部、之后、面板 1 中、面板 2 中、中继器中。我尝试为每个中继器设置多个 updatePanel,我尝试将面板放置在任何地方……我得到的最好结果是面板 1 中的文本框不会丢失其中的信息。 UpdatePanel2 中的图像总是消失(因为我在 pageLoad 上绑定过一次,如果不是回发),repeater1 中的文本框总是会自行重置。最重要的是,当我浏览下拉列表时,OnTick 事件会失去对文本框和左键的关注。

我不知道如何解决这个问题。

编辑:我发现我可以使用 ajax 来构建我的转发器。但我不知道该怎么做。谁能给我解释一下?

【问题讨论】:

    标签: asp.net ajax timer updatepanel repeater


    【解决方案1】:

    将 UpdateMode= "Conditional" 属性添加到您的 UpdatePanel 和绑定中继器集 UpdatePanel1.update(); 后的 OnTick 事件中@


    OnTick 事件

    protected void Timer1_Tick(object sender, EventArgs e)
        {
            BindRepeater();
            UpdatePanel1.update();
        }
    

    【讨论】:

    • 同样的事情仍然发生。我的图像消失了,文本框失去了内容,我失去了焦点。
    • 我稍微调整了我的代码,现在它可以工作了。谢谢
    【解决方案2】:

    在调整了我的页面之后,我得到了这个。

    <asp:Timer runat="server" Interval="5000" OnTick="UpdateTimer_Tick" ID="UpdateTimer" />
    <UpdatePanel1 UpdateMode="Conditional">
    <dropdownlist/>
    <Panel 1>
        <TextBox/><Button/>
    </Panel 1>
    <Repeater 1> //Bound to a list in code behind
        <Checkbox/><textbox/>
    </Repeater 1>
    <Button/>
    </UpdatePanel1>
    
    <UpdatePanel2 UpdateMode="Conditional">
    <Repeater 2> //Bound to a list in code behind
        <button/><button/>
    </Repeater 2>
    </UpdatePanel2>
    
    <UpdatePanel3 UpdateMode="Conditional">
    <Repeater 3> //Bound to a dataset in code behind
        <textbox/><button/><button/>
    </Repeater 3>
    <button/><button/><button/>
    </UpdatePanel3>
    
    <UpdatePanel4 UpdateMode="Conditional">
    <panel 2>
       //Stuff
    </panel 2>
        <Image/>
    </UpdatePanel4>
    

    在后面的代码中使用

    protected void Timer1_Tick(object sender, EventArgs e) 
    { BindRepeater(); UpdatePanel2.Update(); }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多