【发布时间】:2015-06-26 16:22:14
【问题描述】:
我有一个复选框和一个下拉列表,我正在尝试检查是否选中了复选框,是否已从下拉列表中选择了一个值。这很好,但是如果弹出警报消息并且我单击“确定”删除该消息,它会退出我所在的页面。我想说在页面上相同,我不知道为什么它会将我重定向到其他地方.此外,如果可能的话,我希望出现错误消息 ErrorMessage = "Please select" 而不是警告框,但这不是这里的主要问题。
<tr>
<td class="Header">License Type</td>
<td></td>
<td>
<asp:DropDownList runat="server" ID="ddlHazLicenseType" CausesValidation="true" >
</asp:DropDownList>
<asp:CustomValidator id="CustomValidator2" runat="server"
ControlToValidate = "ddlHazLicenseType"
ErrorMessage = "Please select"
ValidateEmptyText="True"
ClientValidationFunction="validateHazLicenceType" >
</asp:CustomValidator>
</td>
</tr>
function validateHazLicenceType()
{
if (document.getElementById("<%=chkHazTrained.ClientID %>").checked)
{
var ddl = document.getElementById("ddlHazLicenseType");
var selectedValue = ddl.options[ddl.selectedIndex].value;
if ($("#ddlHazLicenseType")[0].selectedIndex <= 0)
{
alert("Please select a licence type");
}
}
}
【问题讨论】:
-
如果您可以发布更多页面标记,也许会有所帮助?很难判断您是回发还是提交,使用更新面板等。
标签: javascript jquery asp.net visual-studio