1

我正在使用设置了计时器的更新面板。问题是每当更改计时器时似乎所有更新面板都已刷新并且闪烁,因此我无法在下拉列表中选择值。我怎么解决这个问题。

这是我的代码。

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
            <ContentTemplate>
                <asp:Label ID="Label1" Text="Remaining Time" runat="server"></asp:Label>
                <asp:Label ID="lblTimeSpan" Visible="false" Text="" runat="server"></asp:Label>
                <asp:Label ID="lblRemainingTime" Text="" runat="server"></asp:Label>
                <asp:Timer ID="Timer1" runat="server" OnTick="Timer1_Tick" Enabled="true" Interval="1000" ></asp:Timer>`//Timer`
            </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer1" EventName="Tick" />
            </Triggers>
        </asp:UpdatePanel>
4

1 回答 1

2

要将 UpdatePanel 彼此隔离,请将属性:UpdateMode设置Conditional 为每个更新面板。之后为您的更新面板定义触发器。

例子:

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
     <ContentTemplate> 
         <asp:Label ID="Label1" runat="server" /><br /> 
         <asp:Button ID="Button1" runat="server" Text="Update Panel 1" 
         OnClick="Button1_Click" />         
     </ContentTemplate>
   <Triggers> 
    <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" /> 
   </Triggers> 
 </asp:UpdatePanel>

// IInd 更新面板

<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
 <ContentTemplate> 
    <asp:Label ID="Label2" runat="server" ForeColor="red" /> 
    <asp:Button ID="Button2" runat="server" Text="Update Panel 2" 
         OnClick="Button2_Click" /> 
 </ContentTemplate> 
 <Triggers> 
  <asp:AsyncPostBackTrigger ControlID="Button2" EventName="Click" /> 
 </Triggers> 
</asp:UpdatePanel>

现在点击事件:

// 按钮点击 1

 protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = DateTime.Now.ToLongTimeString(); 

    } 

// 按钮点击 2

protected void Button2_Click(object sender, EventArgs e) 
{ 
     Label2.Text = DateTime.Now.ToLongTimeString(); 
}

正如您现在可以验证的那样,当您单击 时Button1,仅刷新第一个 UpdatePanel。它不会对第二个更新面板[UpdatePanel2]产生任何影响

同样,点击Button2,只会刷新第二个 UpdatePanel。第一个 UpdatePanel 不会刷新。

因此,在您的情况下,为包含下拉列表的 updatePanel 设置 UpdateMode="Conditional"。并确保为您的 2nd Update 面板定义的触发器 [Controls here] 不包含在 firstUpdatePanel 中。

于 2013-09-13T12:34:26.023 回答