[英]Stop enabling Radiobutton after button click?
我的項目中有單選按鈕,如果從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();
}
}
現在的問題是我的網站上有兩個按鈕。 每當我單擊這些按鈕時,即使選擇Maintenance
或Reporting
,單選按鈕也會被激活。 如何禁用它?
在我的頁面加載中:
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!')">
我終於以以下方式解決了該錯誤。
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();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.