2013-02-28 75 views
0

我正面临使用中继器页面上使用定时器的问题。
我的页面基本上是这样的:(没记下所有的标签和非重要的东西,该页面是相当大的)阿贾克斯计时器,更新面板和中继器

<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来构建我的中继器。但我没有线索怎么做。任何人都可以解释我?

回答

1

添加的UpdateMode = “条件”属性为您的UpdatePanel和OnTick事件绑定你的中继设置UpdatePanel1.update();


OnTick事件

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

同一仍然发生。我的图像消失了,文本框内容松散,焦点松动。 – snaplemouton 2013-02-28 15:20:36

+0

我调整了一下我的代码,现在它可以工作。谢谢 – snaplemouton 2013-02-28 17:00:18

0

在对我的页面进行调整后,我最终得到了这个结果。

<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(); }