我的页面有一个向导控件,该向导中有几个控件。我有一个带有两个列表项的单选按钮列表(是和否)。此单选按钮列表将Autopost返回设置为true。原因是,单击是按钮,将显示一个面板,此面板有许多控件。单击否,面板变为不可见。
所以问题是,当我单击是按钮时,将显示面板,如果我然后单击向导控件的下一个按钮,则会显示验证摘要,说明在显示的面板中选择数据。但是,如果我单击否单选按钮,验证摘要仍然会出现,并且回发没有发生。如果我尝试单击否按钮两次(即单击是然后再单击否),则发生回发并且面板变为不可见。
请找到以下代码:
<asp:Label runat="server" ID="lblCompDetails" Text=""></asp:Label>
<asp:RadioButtonList runat="server" ID="rblLaptopPC" RepeatDirection="Horizontal" AutoPostBack="true" OnSelectedIndexChanged="rblLaptopPC_CheckedChanged" CssClass="ListStyle">
<asp:ListItem Value="0" Text="Yes"></asp:ListItem>
<asp:ListItem Value="1" Text="No"></asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="rblLaptopPCValidator" ControlToValidate="rblLaptopPC" Display="Dynamic" ValidationGroup="Required" runat="server" ForeColor="Red" InitialValue="" ToolTip="" ErrorMessage="" Text="*" SetFocusOnError="True"> * </asp:RequiredFieldValidator>
<asp:Panel ID="YesPanel" runat="server" Visible="false" >
<p>
<asp:Label runat="server" ID="lblCompOwner" Text=" AssociatedControlID="rblCompOwner" ></asp:Label>
<asp:RadioButtonList runat="server" ID="rblCompOwner" RepeatDirection="Horizontal" CssClass="ListStyle">
<asp:ListItem Value="0" Text="Own Computer"></asp:ListItem>
<asp:ListItem Value="1" Text="Owned by Local Authority"></asp:ListItem>
<asp:ListItem Value="2" Text="Other"></asp:ListItem>
</asp:RadioButtonList>
<asp:RequiredFieldValidator ID="CompOwnerValidator" ControlToValidate="rblCompOwner" Display="Dynamic" ValidationGroup="Required" runat="server" ForeColor="Red" InitialValue="" ToolTip="" ErrorMessage="" Text="*" SetFocusOnError="True"> * </asp:RequiredFieldValidator>
</p>
<br />
<p>
<asp:Label runat="server" ID="lblLaptopPC" Text=" "></asp:Label>
<asp:RadioButtonList runat="server" ID="LaptopPC" RepeatDirection="Horizontal" CssClass="ListStyle">
<asp:ListItem Value="0" Text="Laptop"></asp:ListItem>
<asp:ListItem Value="1" Text="PC"></asp:ListItem>
</asp:RadioButtonList>
<br />
</p>
<p>
<asp:Label runat="server" ID="lblMSOffice" Text="?"></asp:Label>
<asp:Label ID="lblMSOfficeMsg" runat="server" Text"" CssClass="HighlitedTextCSS"></asp:Label>
<asp:RadioButtonList runat="server" ID="OfficeInstalledPost16" RepeatDirection="Horizontal" CssClass="ListStyle">
<asp:ListItem Value="0" Text="Yes"></asp:ListItem>
<asp:ListItem Value="1" Text="No"></asp:ListItem>
</asp:RadioButtonList>
<br />
</p>
<p>
<asp:Label runat="server" ID="lblCompFirewall" Text="?"></asp:Label>
<asp:RadioButtonList runat="server" ID="FirewallPost16" RepeatDirection="Horizontal" CssClass="ListStyle">
<asp:ListItem Value="0" Text="Yes"></asp:ListItem>
<asp:ListItem Value="1" Text="No"></asp:ListItem>
</asp:RadioButtonList>
<br />
</p>
<p>
<asp:Label runat="server" ID="lblCompAdminRights" Text=" "></asp:Label>
<asp:RadioButtonList runat="server" ID="AdminRightsPost16" RepeatDirection="Horizontal" CssClass="ListStyle">
<asp:ListItem Value="0" Text="Yes"></asp:ListItem>
<asp:ListItem Value="1" Text="No"></asp:ListItem>
</asp:RadioButtonList>
<br />
</p>
</asp:Panel>
protected void rblLaptopPC_CheckedChanged(object sender, EventArgs e)
{
if (rblLaptopPC.SelectedItem.Text == "Yes")
{
YesPanel.Visible = true;
InternetDetailsPanel.Visible = true;
}
else if (rblLaptopPC.SelectedItem.Text == "No")
{
YesPanel.Visible = false;
InternetDetailsPanel.Visible = false;
}
}
答案 0 :(得分:0)
您可能更喜欢在显示面板时禁用基于客户端的基于java脚本的验证,并且仅使用服务器端验证来处理这种复杂的情况。