UpdatePanel 仅回发 RadioButtonList 控件的整个页面
UpdatePanel posting back entire page for the RadioButtonList control only
我的网页上有 3 个 UpdatePanel。他们都工作得很好,多年来一直使用 UpdatePanels,从未遇到过这个问题。
RadioButtonList 正在发回整个页面而不是 UpdatePanel,并且在输出中看不到任何错误。我以前从未见过这种行为并将代码复制到另一个项目中,并且它按预期工作。页面上的所有其他控件都以相同的格式按预期工作。
是否还有其他原因导致此行为发生?我的代码如下:
ASPX代码:
<asp:RadioButtonList ID="rbSelectWeek" runat="server" ClientIDMode="Static" CssClass="rb-select" OnSelectedIndexChanged="rbSelectWeek_SelectedIndexChanged" AutoPostBack="true" >
<asp:ListItem Text="Previous" Value="1" />
<asp:ListItem Text="Current" Value="2" Selected="True" />
<asp:ListItem Text="Next" Value="3" />
<asp:ListItem Text="All" Value="4" />
</asp:RadioButtonList>
<asp:UpdatePanel ID="upCaseViewer" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:HiddenField ID="dtFrom" runat="server" ClientIDMode="Static" Value="1900-01-01" />
<asp:HiddenField ID="dtEnd" runat="server" ClientIDMode="Static" Value="9999-12-31" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="cmbTeam" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="rbSelectWeek" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
VB.Net / C#
Protected Sub rbSelectWeek_SelectedIndexChanged(sender As Object, e As EventArgs) Handles rbSelectWeek.SelectedIndexChanged
Dim sVal As Integer = rbSelectWeek.SelectedValue
rbSelectWeek.ClearSelection()
rbSelectWeek.SelectedValue = sVal
Select Case sVal
Case 1
dtFrom.Value = getFunctions.getPrevWeek("Start")
dtEnd.Value = getFunctions.getPrevWeek("End")
Case 2
dtFrom.Value = getFunctions.getCurrWeek("Start")
dtEnd.Value = getFunctions.getCurrWeek("End")
Case 3
dtFrom.Value = getFunctions.getNextWeek("Start")
dtEnd.Value = getFunctions.getNextWeek("End")
Case Else
dtFrom.Value = getFunctions.getAll("Start")
dtEnd.Value = getFunctions.getAll("End")
End Select
End Sub
当引用的元素使用 ClientIDMode="Static"
时,AsyncPostBackTriggers 不起作用。所以改成
<asp:RadioButtonList ID="rbSelectWeek" runat="server" CssClass="rb-select" OnSelectedIndexChanged="rbSelectWeek_SelectedIndexChanged" AutoPostBack="true" >
<asp:ListItem Text="Previous" Value="1" />
<asp:ListItem Text="Current" Value="2" Selected="True" />
<asp:ListItem Text="Next" Value="3" />
<asp:ListItem Text="All" Value="4" />
</asp:RadioButtonList>
我的网页上有 3 个 UpdatePanel。他们都工作得很好,多年来一直使用 UpdatePanels,从未遇到过这个问题。
RadioButtonList 正在发回整个页面而不是 UpdatePanel,并且在输出中看不到任何错误。我以前从未见过这种行为并将代码复制到另一个项目中,并且它按预期工作。页面上的所有其他控件都以相同的格式按预期工作。
是否还有其他原因导致此行为发生?我的代码如下:
ASPX代码:
<asp:RadioButtonList ID="rbSelectWeek" runat="server" ClientIDMode="Static" CssClass="rb-select" OnSelectedIndexChanged="rbSelectWeek_SelectedIndexChanged" AutoPostBack="true" >
<asp:ListItem Text="Previous" Value="1" />
<asp:ListItem Text="Current" Value="2" Selected="True" />
<asp:ListItem Text="Next" Value="3" />
<asp:ListItem Text="All" Value="4" />
</asp:RadioButtonList>
<asp:UpdatePanel ID="upCaseViewer" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:HiddenField ID="dtFrom" runat="server" ClientIDMode="Static" Value="1900-01-01" />
<asp:HiddenField ID="dtEnd" runat="server" ClientIDMode="Static" Value="9999-12-31" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="cmbTeam" EventName="SelectedIndexChanged" />
<asp:AsyncPostBackTrigger ControlID="rbSelectWeek" EventName="SelectedIndexChanged" />
</Triggers>
</asp:UpdatePanel>
VB.Net / C#
Protected Sub rbSelectWeek_SelectedIndexChanged(sender As Object, e As EventArgs) Handles rbSelectWeek.SelectedIndexChanged
Dim sVal As Integer = rbSelectWeek.SelectedValue
rbSelectWeek.ClearSelection()
rbSelectWeek.SelectedValue = sVal
Select Case sVal
Case 1
dtFrom.Value = getFunctions.getPrevWeek("Start")
dtEnd.Value = getFunctions.getPrevWeek("End")
Case 2
dtFrom.Value = getFunctions.getCurrWeek("Start")
dtEnd.Value = getFunctions.getCurrWeek("End")
Case 3
dtFrom.Value = getFunctions.getNextWeek("Start")
dtEnd.Value = getFunctions.getNextWeek("End")
Case Else
dtFrom.Value = getFunctions.getAll("Start")
dtEnd.Value = getFunctions.getAll("End")
End Select
End Sub
当引用的元素使用 ClientIDMode="Static"
时,AsyncPostBackTriggers 不起作用。所以改成
<asp:RadioButtonList ID="rbSelectWeek" runat="server" CssClass="rb-select" OnSelectedIndexChanged="rbSelectWeek_SelectedIndexChanged" AutoPostBack="true" >
<asp:ListItem Text="Previous" Value="1" />
<asp:ListItem Text="Current" Value="2" Selected="True" />
<asp:ListItem Text="Next" Value="3" />
<asp:ListItem Text="All" Value="4" />
</asp:RadioButtonList>