UpdatePanel的定时器会导致所有面板更新

编程入门 行业动态 更新时间:2024-10-28 01:12:55
本文介绍了UpdatePanel的定时器会导致所有面板更新的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有几个UpdatePanel的ASP.NET Web窗体,我想有只触发这些UpdatePanel的更新中的一个定时器。然后,我想要一个单独的UpdatePanel在一个DropDownList的OnSelectedIndexChanged事件更新。在code我将更新定时器触发面板就好了,但是当我更改索引,下拉触发面板会等到下一个计时器周期进行更新。怎样才可以有下拉触发面板会立即更新?低于code。

C#:

公共部分类WebForm2:System.Web.UI.Page{    保护无效的Page_Load(对象发件人,EventArgs的发送)    {    }    保护无效Timer1_Tick(对象发件人,EventArgs的发送)    {        Label1.Text =UpdatePanel1刷新在:+      DateTime.Now.ToLongTimeString();    }    保护无效dropDown_indexChange(对象发件人,EventArgs的发送)    {        Label2.Text =UpdatePanel2刷新在:+          DateTime.Now.ToLongTimeString();        //UpdatePanel2.Update(); - 没有帮助    }}

ASP:

<表ID =form1的=服务器>< D​​IV>    < ASP:的ScriptManager ID =ScriptManager1=服务器>< / ASP:ScriptManager的>    < BR />    < ASP:的UpdatePanel ID =UpdatePanel1=服务器的UpdateMode =条件>        <&的ContentTemplate GT;            < ASP:标签ID =Label1的=服务器文本=没有更新>< / ASP:标签>            < ASP:定时器ID =定时器=服务器间隔=3000ontick =Timer1_Tick>< / ASP:定时器>        < /&的ContentTemplate GT;        <&触发器GT;            < ASP:AsyncPostBackTrigger控件ID =定时器事件名称=嘀/>        < /触发器>    < / ASP:的UpdatePanel>    < BR />    < ASP:的UpdatePanel ID =UpdatePanel2=服务器的UpdateMode =条件>        <&的ContentTemplate GT;            < ASP:标签ID =Label2的=服务器文本=还没有更新>< / ASP:标签>        < /&的ContentTemplate GT;        <&触发器GT;            < ASP:AsyncPostBackTrigger控件ID =DropDownList1事件名称=的SelectedIndexChanged/>        < /触发器>    < / ASP:的UpdatePanel>    < BR />    < BR />    < ASP:DropDownList的OnSelectedIndexChanged =dropDown_indexChangeID =DropDownList1=服务器>        < ASP:列表项>这< / ASP:ListItem的>        < ASP:ListItem的>这< / ASP:ListItem的>        < ASP:列表项>在其它< / ASP:ListItem的>    < / ASP:DropDownList的>< / DIV>< /表及GT;

解决方案

移动你的DropDownList成一个UpdatePanel并设置 .AutoPostBack = TRUE 就可以了。

I have an ASP.NET web form with several UpdatePanels and I would like to have a timer that triggers only one of these UpdatePanels to update. I then want a separate UpdatePanel to update on the OnSelectedIndexChanged event of a DropDownList. The code I have will update the timer-triggered panel just fine, but when I change the index, the drop down-triggered panel will wait until the next timer tick to update. How can I have the drop down-triggered panel update instantaneously? Code below.

C#:

public partial class WebForm2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Timer1_Tick(object sender, EventArgs e) { Label1.Text = "UpdatePanel1 refreshed at: " + DateTime.Now.ToLongTimeString(); } protected void dropDown_indexChange(object sender, EventArgs e) { Label2.Text = "UpdatePanel2 refreshed at: " + DateTime.Now.ToLongTimeString(); //UpdatePanel2.Update(); -- Didn't help } }

ASP:

<form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <br /> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Label ID="Label1" runat="server" Text="not updated yet"></asp:Label> <asp:Timer ID="Timer1" runat="server" Interval="3000" ontick="Timer1_Tick"></asp:Timer> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" /> </Triggers> </asp:UpdatePanel> <br /> <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Label ID="Label2" runat="server" Text="also not updated yet"></asp:Label> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel> <br /> <br /> <asp:DropDownList OnSelectedIndexChanged="dropDown_indexChange" ID="DropDownList1" runat="server"> <asp:ListItem>This</asp:ListItem> <asp:ListItem>That</asp:ListItem> <asp:ListItem>The Other</asp:ListItem> </asp:DropDownList> </div> </form>

解决方案

Move your DropDownList into an UpdatePanel and set .AutoPostBack = true on it.

更多推荐

UpdatePanel的定时器会导致所有面板更新

本文发布于:2023-11-25 00:18:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1627518.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:定时器   面板   UpdatePanel

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!