1

我有一个 javascript 函数,其中基于选择我必须启用一行并禁用同一页面上的按钮。早些时候,它是通过后面的代码处理的,并且使用相同的逻辑可以正常工作。现在它不起作用。

JS函数:

function ValidateRadioButtonList()
{         
   var RBL = document.getElementById('<%=rbListExamShot.ClientID%>');
   var radiobuttonlist = RBL.getElementsByTagName("input");
   var counter = 0;
   var atLeast = 1
   for (var i = 0; i < radiobuttonlist.length; i++) {
   if (radiobuttonlist[i].checked) {

   counter++;
   var selected = i;
   }
   }
   if (atLeast = counter) {
   // return arguments.IsValid;
   var RowMessage = document.getElementById  ('<%                               =RowCliamMessage.ClientID%>');
   RowMessage.style.display = "block";
   }
   else {

   RowMessage.style.display = "none";
   }
   if (selected == 1) {

   var Submit = document.getElementById('<%=Save.ClientID%>');
   Submit.disabled = true;
   return false;
   }
   else {
   return true;
   }
 } 

asp.net 控制和验证器:

   <td  align="left">
            <asp:RadioButtonList CssClass="label" ID="rbListExamShot" runat="server" AutoPostBack="true"
                RepeatDirection="Horizontal" ValidationGroup="Save"  
                onselectedindexchanged="rbListExamShot_SelectedIndexChanged">
                <asp:ListItem Text="Single Shot" Value="1"></asp:ListItem>
                <asp:ListItem Text="Double Shot" Value="2"></asp:ListItem>
            </asp:RadioButtonList>
            </td>
            <td>
              <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" Text="Please select voucher type"
                Display="Dynamic" ControlToValidate="rbListExamShot" ValidationGroup="Save"
                ForeColor="Red" Font-Bold="False"></asp:RequiredFieldValidator>
                 <asp:CustomValidator ID="CustomValidator1" runat="server" ValidationGroup="Save"
                Display="Dynamic" ErrorMessage=".Double Shot Vouchers cannot be reimbursed."
                ControlToValidate="rbListExamShot" ClientValidationFunction="ValidateRadioButtonList"
                ForeColor="Red" Font-Bold="False"></asp:CustomValidator>
        </td>
4

2 回答 2

1

感谢大家的评论..问题是我在 var 中获取客户端 ID,然后尝试设置属性..现在我正在做类似的事情:document.getElementById('<%=Save.ClientID%>')。 disabled = true ..它对我有用!谢谢大家

于 2012-10-18T13:55:01.110 回答
-1
<td  align="left">
        <asp:RadioButtonList CssClass="label" ID="rbListExamShot" runat="server" AutoPostBack="true"
            RepeatDirection="Horizontal" ValidationGroup="Save"  
            onselectedindexchanged="rbListExamShot_SelectedIndexChanged();">
            <asp:ListItem Text="Single Shot" Value="1"></asp:ListItem>
            <asp:ListItem Text="Double Shot" Value="2"></asp:ListItem>
        </asp:RadioButtonList>
        </td>
        <td>
          <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" Text="Please select voucher type"
            Display="Dynamic" ControlToValidate="rbListExamShot" ValidationGroup="Save"
            ForeColor="Red" Font-Bold="False"></asp:RequiredFieldValidator>
             <asp:CustomValidator ID="CustomValidator1" runat="server" ValidationGroup="Save"
            Display="Dynamic" ErrorMessage=".Double Shot Vouchers cannot be reimbursed."
            ControlToValidate="rbListExamShot" ClientValidationFunction="ValidateRadioButtonList"
            ForeColor="Red" Font-Bold="False"></asp:CustomValidator>
    </td>
于 2012-10-18T10:10:25.727 回答