[英]How to work with two update panels on same .aspx page
I have two update panels on a page. 我在页面上有两个更新面板。 And I want to update both of them conditions at different-2 conditions.
我想在不同的条件下更新它们的两个条件。 But I don't know why this is not happening.
但我不知道为什么会发生这种情况。 I have specified triggers for both but not helpful, below is my code.
我已为两者指定了触发器,但没有帮助,下面是我的代码。
Please let me know Where I am wrong. 请让我知道我哪里错了。
Actually there are three dropdown lists in first update panel when their selectedindexchange is fired then the second update panel's content also updates. 实际上,当第一个更新面板中的selectedindexchange被触发时,第一个更新面板中有三个下拉列表,然后第二个更新面板的内容也会更新。
<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>
<asp:DropDownList ID="ddlArea" runat="server" Width="200px" DataTextField="AreaName"
DataValueField="Areaid" AutoPostBack="true" OnSelectedIndexChanged="ddlArea_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="ddlRoom" runat="server" Width="200px" DataTextField="RoomName"
DataValueField="Roomid">
</asp:DropDownList>
</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 as follow:- 第二个如下: -
<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>
First of all I would like to recall the use of UpdateMode
首先,我想回忆一下
UpdateMode
的用法
Always
The panel will update its content on every post on the page, they can be partial rendering posts or full posts, in both cases the content of the panel will be updated Always
该面板将在页面上的每个帖子上更新其内容,它们可以是部分呈现帖子或完整帖子,在这两种情况下,面板的内容都将更新
Conditional
The content of the panel will only be updated when different conditions are met: Conditional
只有满足不同条件时,才会更新面板的内容:
By default the events triggered by its child objects will trigger an update, you can change this behavior setting ChildrenAsTriggers="false"
默认情况下,由其子对象触发的事件将触发更新,您可以更改此行为设置
ChildrenAsTriggers="false"
When you declare a trigger in the Triggers
section of the UpdatePanel
在
UpdatePanel
的“ Triggers
部分中声明Triggers
When you explicitly call the UpdatePanel.Update()
method 显式调用
UpdatePanel.Update()
方法时
Full page posts will trigger the update 整页帖子将触发更新
The following code does the following: 以下代码执行以下操作:
Each UpdatePanel is updated when its child controls raise an event 每个UpdatePanel在其子控件引发事件时更新
The UpdatePanel 1 named: up1
will be updated only when its child controls raise an event 名为:
up1
的UpdatePanel 1 仅在其子控件引发事件时才会更新
The UpdatePanel 2 named up2
will be updated when its child controls raise an event 名为
up2
的UpdatePanel 2将在其子控件引发事件时更新
The UpdatePanel 2 named up2
will also be updated when the triggers defined are fired, in this case, when the DropDownList
named ddl1OnPanel1
on the UpdatePanel 1 fires its SelectedIndexChanged
名为
up2
的UpdatePanel 2也会在触发定义的触发器时更新,在这种情况下,当UpdatePanel 1上名为ddl1OnPanel1
的DropDownList
触发其SelectedIndexChanged
The UpdatePanel 2 named up2
will also be updated when the DropDownList
named ddl2OnPanel1
on the UpdatePanel 1 raises its SelectedIndexChanged
, because in code it explicitly calls: this.up2.Update();
在UpdatePanel 2名为
up2
也将在更新DropDownList
命名ddl2OnPanel1
上的UpdatePanel 1提高其SelectedIndexChanged
:,因为在代码它明确要求this.up2.Update();
I think that tweaking this code, you could achieve your desired goal, just copy paste it on a new page and run it 我认为通过调整此代码,您可以实现所需的目标,只需将其粘贴到新页面并运行即可
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();
}
<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>
You could change the UpdateMode="Always"
on the UpdatePanel 2, to see the difference, if you do it, this panel will be updated on every post, either full posts or posts coming from the UpdatePanel1 您可以更改UpdatePanel 2上的
UpdateMode="Always"
,以查看差异,如果您这样做,此面板将在每个帖子上更新,包括来自UpdatePanel1的完整帖子或帖子
Remove the Autopostback="True" from the DropdownLists if you want an asyncpostback to happen. 如果要进行异步后备,请从DropdownLists中删除Autopostback =“True”。 Also, what exactly is wrong at the moment?
此外,目前究竟出现了什么问题? The updatepanels don't update at all?
updatepanels根本没有更新?
EDIT. 编辑。 Also remove childrenAsTriggers as it is not needed at this occasion
同时删除childrenAsTriggers,因为此时不需要
I used this successfully for 4 updatepanel. 我成功使用了4个updatepanel。
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server" EnableScriptGlobalization="true" CombineScripts="false" ScriptMode="Release">
</asp:ToolkitScriptManager>
If you are using nested update panels refer below 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 not using nested update panels then remove "UpdateMode" conditions from both Updatepanels of your code. 如果不使用嵌套更新面板,则从代码的两个Updatepanel中删除“UpdateMode”条件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.