以下是我的代码的测试场景。1) 一旦用户选择了 Webpage.aspx 上的一个单选按钮,就会出现一个模态弹出扩展器。2) 在模式弹出窗口中定义了一个用户控件 (SSL_Ticket.ascx)。3) 为包含在用户控件内的下拉列表定义了一个RequiredFieldValidator。4) 如果用户从下拉列表中选择“0”值,则不会显示验证错误消息。
代码
网页.aspx
<asp:RadioButtonList ID="RadioButtonListForTicket" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="radioButtonListForTicket_OnSelectedIndexChanged">
<asp:ListItem Selected="True">No</asp:ListItem>
<asp:ListItem>Yes</asp:ListItem>
</asp:RadioButtonList>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtenderForTicket" runat="server" BackgroundCssClass="popUpStyle"
DropShadow="true" PopupControlID="divTicketPreview" PopupDragHandleControlID="panelDragHandle"
TargetControlID="btnForPopupAppear" CancelControlID="btnForPopupDisappear"/>
…………
_
网页.aspx.cs
protected void radioButtonListForTicket_OnSelectedIndexChanged(object sender, System.EventArgs e)
{
if (RadioButtonListForTicket.SelectedItem.Text.ToString().Equals("Yes"))
{
// Check if the sites are selected
updateSelectionCount();
updateListOfSites();
if (selectionCount == 0)
{
lblSSLTicketSelection.Text = "Please select a site.";
RadioButtonListForTicket.SelectedValue = "No";
return;
}
else
{
lblSSLTicketSelection.Text = "";
}
....
ModalPopupExtenderForTicket.Show();
}
}
...
SSL_Ticket.ascx
<asp:DropDownList ID="cmbRootCause" runat="server" Width="255px" OnSelectedIndexChanged="cmbRootCause_SelectedIndexChanged" AutoPostBack="true"
CausesValidation="true">
<asp:ListItem Value="0">Select</asp:ListItem>
<asp:ListItem Value="1">Item1</asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="reqdFieldForRootCause" runat="server" ControlToValidate="cmbRootCause" InitialValue="Select"
ErrorMessage="Please select root cause" ValidationGroup="validateRootCause" Visible="false" Display="Dynamic" EnableClientScript="true">
</asp:RequiredFieldValidator>
...
SSL_Ticket.ascx.cs
protected void cmbRootCause_SelectedIndexChanged(object sender, EventArgs e)
{
if (cmbRootCause.SelectedItem.ToString().Equals("Other"))
{
lblcmbRootCause.Text = "";
lblcmbRootCause.Visible = false;
txtRootCauseOther.Visible = true;
}
else if (cmbRootCause.SelectedItem.ToString().Equals("Select"))
{
lblcmbRootCause.Visible = true;
lblcmbRootCause.Text = "Please select root cause";
}
else
{
lblcmbRootCause.Text = "";
lblcmbRootCause.Visible = false;
txtRootCauseOther.Visible = false;
}
}
我确实浏览了几个解决方案(ValidateProperty、客户端验证、RangeValidation 等),但它没有触发验证文本。
这没有帮助 -在用户控件中处理 RequiredFieldValidator
非常感谢您的帮助。
谢谢!!!