我在ASP .NET中实现了两个下拉列表,但是我使用jQuery在客户端进行一些检查,这是场景:用户从ddl1中选择一个选项,然后当从ddl2中选择一个特定项目时ddl1中的一个项目应该被删除或禁用,将通知用户。 在jQuery代码下面: 在ASP .NET中我使用" Onchange"调用方法
var myTest = function () {
var val1 = $('#ContentPlaceHolder1_ddlGxP').val();
var val2 = $('#ContentPlaceHolder1_ddlFinalizedMethod').val();
console.log('glpvalue: ' + val1);
console.log('finalizedmethod: ' + val2);
if (val1 === '3' && val2 === '2') {
// document.getElementById('<%=txtComments.ClientID%>').value = "!Please Insert another GLP Method.";
$("#ContentPlaceHolder1_ddlGxP[value='3']").remove();
$("#ContentPlaceHolder1_RequiredFieldValidator10").css({"visibility": "visible", "color": "red"});
//alert('! Please select another GxP Standard');
$(':input[type="submit"]').prop('disabled', true);
}
else {
$(':input[type="submit"]').prop('disabled', false);
$("#ContentPlaceHolder1_ddlGxP[value='3']").remove();
$("#ContentPlaceHolder1_RequiredFieldValidator10").css({ "visibility": "hidden", "color": "red" });
}
问题是我的ddl1项目未被删除。
ddl1的实现
<div>
<asp:Label ID="Label2" runat="server" CssClass="stdLabel">GxP standard <span class="mandatory"> *</span></asp:Label>
if (userRole == ("Administrator") ||
<asp:DropDownList ID="ddlGxP" runat="server" CssClass="stdDropdownSmall" OnSelectedIndexChanged="ddlGxP_SelectedIndexChanged" AutoPostBack="true" />
<asp:RequiredFieldValidator ID="RFVddlGxP" runat="server" ControlToValidate="ddlGxP" InitialValue="0" CssClass="RequiredFieldError" ErrorMessage=" ! Please insert" />
else
<asp:TextBox ID="txtGxPDisabled" runat="server" CssClass="stdTextboxSmallDisabled" Enabled="false" />
}
</div>
ddl2的实施
<div>
if (!string.IsNullOrEmpty(txtFinalized.Text))
{
<asp:Label ID="Label23" runat="server" CssClass="stdLabel">Finalized Method<span class="mandatory"> *</span></asp:Label>
<%}
else
{
<asp:Label ID="Label17" runat="server" CssClass="stdLabel">Finalized Method </asp:Label>
}
if (userRole == ("Administrator") ||
userRole == ("Expert") ||
(userRole == ("User") && (txtOwner.Text == "" || txtOwner.Text.ToUpper() == userName.ToUpper())))
{
<asp:DropDownList ID="ddlFinalizedMethod" runat="server" CssClass="stdDropdown" OnSelectedIndexChanged="ddlGxP_SelectedIndexChanged" AutoPostBack="true" onchange="myTest()" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" ControlToValidate="ddlFinalizedMethod" InitialValue="0" CssClass="RequiredFieldError" ErrorMessage=" !Please select another Standard" />
}
else
{
<asp:TextBox ID="txtFinalizedMethodDisabled" runat="server" CssClass="stdTextboxSmallDisabled" Enabled="false" />
}
</div>
答案 0 :(得分:0)
您的问题是您正在删除客户端上的选项,但是您将自动回发整个表单 - 因此,一旦您的服务器端代码呈现控件,它就具有所有原始元素。如果您希望更改保持不变,服务器将需要了解客户端所做的更改 - 或者您必须管理服务器端的所有内容。