点击按钮后停止启用Radiobutton?

时间:2012-12-19 03:34:23

标签: 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);");
}

2 个答案:

答案 0 :(得分:0)

我用过这个

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

答案 1 :(得分:0)

我终于以下列方式解决了错误。

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

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

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