0

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>
John Engel-Kemnetz
  • 2,527
  • 22
  • 22

1 Answers1

2

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

Richard
  • 29,854
  • 11
  • 77
  • 120