2012-07-24 38 views
0

我有一个ASP.NET Web窗体与几个UpdatePanels,我想有一个计时器只触发其中一个UpdatePanel更新。然后我想要一个单独的UpdatePanel更新DropDownList的OnSelectedIndexChanged事件。我有的代码会更新定时器触发面板,但是当我更改索引时,下拉触发面板将一直等到下一个定时器打勾更新。我怎样才能立即下拉触发面板更新?下面的代码。UpdatePanel计时器导致所有面板更新

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> 

回答

2

移动你的DropDownList到一个UpdatePanel并在其上设置.AutoPostBack = true

+0

谢谢,这正是我一直在寻找的! – 2012-07-24 15:49:56