c# - 单击按钮后停止启用单选按钮?

标签 c# javascript asp.net radio-button

我的项目中有单选按钮,如果选择了 4 个属性列表中的 2 个选项之一,这些单选按钮应该被禁用。这是我的代码:

<asp:DropDownList ID="drpLType" runat="server" CssClass="drp">
 <asp:ListItem Value="0" Selected="True">Professional</asp:ListItem>
 <asp:ListItem Value="1">Enterprise</asp:ListItem>
 <asp:ListItem Value="2">Maintanence</asp:ListItem>
 <asp:ListItem Value="3">Reporting</asp:ListItem>
</asp:DropDownList>

我为此使用了 javascript:

function funMeapSupportValidate(val)
{
  switch(val)
    {
        case "0" :                             
            document.getElementById('<%=this.rdoMeapSupport.ClientID%>').disabled = false; 
            break;
        case "1" :
            document.getElementById('<%=this.rdoMeapSupport.ClientID%>').disabled = false; 
            break;                
        case  "2" :
            document.getElementById('<%=this.rdoMeapSupport.ClientID%>').check = false;   
            document.getElementById('<%=this.rdoMeapSupport.ClientID%>').disabled = true; 
            break;                
        case  "3" :
            document.getElementById('<%=this.rdoMeapSupport.ClientID%>').check = false;   
             document.getElementById('<%=this.rdoMeapSupport.ClientID%>').disabled = true; 
            break;                
        default:
            break;
    }
}

在我的后端代码中:

protected void drpLType_SelectedIndexChanged(object sender, EventArgs e)
{
    if (drpLType.SelectedValue == "Professional")
    {
        rdoMeapSupport.Enabled = true;
    }

    if (drpLType.SelectedValue == "Enterprise")
    {
        rdoMeapSupport.SelectedValue = null;
        rdoMeapSupport.Enabled = true;
    }

    if ((drpLType.SelectedValue == "Maintanence") || (drpLType.SelectedValue == "Reporting"))
    {
        rdoMeapSupport.Enabled = false;
        rdoMeapSupport.ClearSelection();
    }

}

现在的问题是我的网站上有两个按钮。每当我单击这些按钮时,即使我选择了 MaintenanceReporting ,单选按钮也会被激活。我该如何禁用它?

在我的页面加载中:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        Tab1.CssClass = "Clicked";
        MainView.ActiveViewIndex = 0;

        if (drpLType.SelectedValue == "Professional")
        {
            rdoMeapSupport.Enabled = true;
            rdoMeapSupport.SelectedValue = "Yes";
        }

        drpLType_SelectedIndexChanged();
    }

    drpLType.Attributes.Add("onchange", "javascript:funMeapSupportValidate(this.value);");
}

最佳答案

我用过这个

<INPUT type="radio" name="myButton" value="theValue"
onclick="this.checked=false;
alert('Sorry, this option is not available!')">

关于c# - 单击按钮后停止启用单选按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13945116/

相关文章:

javascript - 使用jquery包裹在主div中时如何在两个段落之间添加div标签

c# - 在 C# 中调用 UnmanagedFunctionPointer 以实现自定义调用约定

c# - DataTemplate 是否可以按类型应用于 DataGridTemplateColumn?

javascript - 如何在 Angular.JS 中创建 Javascript 节点

asp.net - Ninject 程序集与引用的程序集不匹配

asp.net - 允许远程访问 IIS 7.5

c# - 将 C# 属性完全按照属性类型命名还是使用更短的字符串更好?

c# - Entity Framework 自动增量键

javascript - ExpressJS/NodeJS/ promise : Return early from promise chain

javascript - jqGrid根据列数动态shrinkToFit