How to work with two update panels on the same .aspx page

I have two update panels per page. And I want to update both conditions under different conditions. But I do not know why this is not happening. I have specified triggers for both, but not useful, below is my code.

Please let me know where I am going wrong.

In fact, on the first update panel there are three drop-down lists when their selectedindexchange is launched, and the contents of the second update panel are also updated.

<asp:UpdatePanel ID="upSearch" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional"> <ContentTemplate> <div style="float: left; width: auto;"> <asp:DropDownList ID="ddlLocation" runat="server" Width="206px" DataTextField="LocationName" DataValueField="Locationid" AutoPostBack="true" OnSelectedIndexChanged="ddlLocation_SelectedIndexChanged"> </asp:DropDownList> &nbsp; <asp:DropDownList ID="ddlArea" runat="server" Width="200px" DataTextField="AreaName" DataValueField="Areaid" AutoPostBack="true" OnSelectedIndexChanged="ddlArea_SelectedIndexChanged"> </asp:DropDownList> &nbsp; <asp:DropDownList ID="ddlRoom" runat="server" Width="200px" DataTextField="RoomName" DataValueField="Roomid"> </asp:DropDownList> &nbsp; </div> <div style="float: left; width: 80px;"> <asp:Button ID="btnSearch" runat="server" Text="Search" ValidationGroup="vgSearch" CssClass="bluebtn" UseSubmitBehavior="false" OnClick="btnSearch_Click" /> </div> <div style="float: left; width: 99%; padding: 5px 0px;"> </div> </ContentTemplate> </asp:UpdatePanel> 

And the second one is: -

 <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true" UpdateMode="Conditional"> <ContentTemplate> <asp:Calendar ID="calSchedule" runat="server" NextPrevFormat="FullMonth" OnDayRender="calSchedule_DayRender" OnVisibleMonthChanged="calSchedule_VisibleMonthChanged"> <DayHeaderStyle CssClass="dayheaderStyle" /> <NextPrevStyle /> <OtherMonthDayStyle BackColor="#ffffff" /> <SelectedDayStyle /> <TitleStyle CssClass="titleStyle" /> <TodayDayStyle BackColor="#ffffa0" ForeColor="#6699cc" /> <WeekendDayStyle /> <DayStyle CssClass="dayStyle" /> </asp:Calendar> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="btnSearch" EventName="Click" /> </Triggers> </asp:UpdatePanel> 
+9
source share
4 answers

First of all, I would like to recall the use of UpdateMode

  • Always The panel will update its content in each message on the page, they can be partial messages about publication or full messages, in both cases the contents of the panel will be updated

  • Conditional contents of the panel will be updated only if various conditions are met:

    • By default, events triggered by its children trigger an update, you can change this behavior parameter ChildrenAsTriggers="false"

    • When you declare a trigger in the Triggers UpdatePanel section

    • When you explicitly call the UpdatePanel.Update() method

    • Full page messages will trigger an update

The following code does the following:

  • Each UpdatePanel is updated when its child controls raise an event.

  • UpdatePanel 1 named: up1 will only be updated when its child controls raise an event

  • UpdatePanel 2 named up2 will update when its child controls raise an event

  • UpdatePanel 2 with the name up2 will also be updated when triggers are triggered, in this case when DropDownList with the name ddl1OnPanel1 on UpdatePanel 1 starts it SelectedIndexChanged

  • An UpdatePanel 2 named up2 will also be updated when a DropDownList named ddl2OnPanel1 in UpdatePanel 1 calls its SelectedIndexChanged , because in the code it explicitly calls: this.up2.Update();

I think that with the setup of this code you could achieve the desired goal, just copy it to a new page and run it

Check the following code (see how the labels displaying the date differ depending on the events raised):

Code for

  protected void ddl1OnPanel1_SelectedIndexChanged(object sender, EventArgs e) { this.lblMessageOnPanel1.Text = "From ddl1 " + DateTime.Now.ToString(); this.calendarOnPanel2.SelectedDate = DateTime.Today.AddDays(1); this.lblMessageOnPanel2.Text = "From ddl1 " + DateTime.Now.ToString(); } protected void ddl2OnPanel1_SelectedIndexChanged(object sender, EventArgs e) { this.lblMessageOnPanel1.Text = "From ddl2 " + DateTime.Now.ToString(); this.calendarOnPanel2.SelectedDate = DateTime.Today.AddDays(2); this.lblMessageOnPanel2.Text = "From ddl2 " + DateTime.Now.ToString(); this.up2.Update(); } 

Aspx

  <asp:ScriptManager runat="server" ID="scriptManager" /> <asp:Button Text="Full Post" runat="server" /> <br /> <asp:UpdatePanel runat="server" ID="up1" UpdateMode="Conditional"> <ContentTemplate> <asp:DropDownList runat="server" ID="ddl1OnPanel1" AutoPostBack="true" OnSelectedIndexChanged="ddl1OnPanel1_SelectedIndexChanged"> <asp:ListItem Text="text1" /> <asp:ListItem Text="text2" /> </asp:DropDownList> <br /> <asp:DropDownList runat="server" ID="ddl2OnPanel1" AutoPostBack="true" OnSelectedIndexChanged="ddl2OnPanel1_SelectedIndexChanged"> <asp:ListItem Text="text3" /> <asp:ListItem Text="text4" /> </asp:DropDownList> <br /> <asp:Label runat="server" ID="lblMessageOnPanel1" /> <br /> <asp:Button ID="Button1" Text="text" runat="server" /> <br /> On every post on Panel 1: <%:DateTime.Now %> </ContentTemplate> </asp:UpdatePanel> <br /> <br /> <asp:UpdatePanel runat="server" ID="up2" UpdateMode="Conditional"> <ContentTemplate> <asp:Calendar ID="calendarOnPanel2" runat="server" > <DayHeaderStyle CssClass="dayheaderStyle" /> <NextPrevStyle /> <OtherMonthDayStyle BackColor="#ffffff" /> <SelectedDayStyle /> <TitleStyle CssClass="titleStyle" /> <TodayDayStyle BackColor="#ffffa0" ForeColor="#6699cc" /> <WeekendDayStyle /> <DayStyle CssClass="dayStyle" /> </asp:Calendar> <br /> <asp:Label ID="lblMessageOnPanel2" runat="server" /> <br /> On every post On Panel 2: <%:DateTime.Now %> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="ddl1OnPanel1" EventName="SelectedIndexChanged" /> </Triggers> </asp:UpdatePanel> 

Easy exit

enter image description here

You can change UpdateMode="Always" to UpdatePanel 2 to see the difference. If you do this, this panel will be updated in every message, whether it is full messages or messages coming from UpdatePanel1

+19
source

Remove Autopostback = "True" from the DropdownLists list if you want an asynchronous transition to occur. Also, what exactly is wrong at the moment? Updates are not updated at all?

EDIT. Also remove childrenAsTriggers as it is not needed for this reason

0
source

I have successfully used this for 4 updates.

 <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %> <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnableScriptGlobalization="true" CombineScripts="false" ScriptMode="Release"> </asp:ToolkitScriptManager> 
0
source

If you use nested update panels, see the sample code:

 <asp:UpdatePanel id="UpdatePanel1" UpdateMode="Conditional" runat="server"> <ContentTemplate> <fieldset> <legend>Parent UpdatePanel</legend> Last refresh <%=DateTime.Now.ToString() %> <br /> <asp:Button ID="Button1" runat="server" Text="Refresh Outer Panel" /> <asp:UpdatePanel ID="UpdatePanel2" runat="server"> <ContentTemplate> <fieldset> <legend>Nested UpdatePanel</legend> Last refresh <%=DateTime.Now.ToString() %> <br /> <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar> </fieldset> </ContentTemplate> </asp:UpdatePanel> </fieldset> </ContentTemplate> </asp:UpdatePanel> 

If you do not use the nested update panels, remove the "UpdateMode" conditions from both update modules of your code.

-one
source

All Articles