2016-03-07 62 views
2

我想在服务器端访问HTML control,但同时加入runat= server,它给我的错误作为添加RUNAT服务器HTML控件给错误

“chkA1 <%#(Container.RecordIndex)%> '不是有效的标识符。

这里是我的html

<input type="checkbox" runat="server" id="chkA1<%# (Container.RecordIndex)%>" name="chkAC1" style="width: 17px; 
               height: 17px;" value="<%# (Container.RecordIndex)%>" onclick="AppoveCheckA(this)" /> 

当我删除runat=server它工作正常。

为什么它不能与runat=server一起使用。任何建议

UPDATE

ID用相应的复选框的变化。这里是我写的代码

var checkBoxID; 
    var status; 
    var arrA = []; 
    var arrB = []; 
    var rowIndex 
    function AppoveCheckA(chk) { 
     status = true; 
     checkBoxID = $(chk).attr("id"); 
     funClientSelectAfter(status, checkBoxID); 
    } 
    function AppoveCheckB(chk) { 
     status = true; 
     checkBoxID = $(chk).attr("id"); 
     funClientSelectAfter1(status, checkBoxID); 
    } 

    function funClientSelectAfter(status, checkBoxID) { 
     if (status && checkBoxID != null) { 
      var len = checkBoxID.length; 

      if (len >= 7) { 
       rowIndex = checkBoxID.substring(checkBoxID.length - 2, checkBoxID.length); 
      } 
      else { 
       rowIndex = checkBoxID.substring(checkBoxID.length - 1, checkBoxID.length); 

      } 
      for (var col = 1; col <= 4; col++) { 
       if (("chkA" + col + rowIndex) == checkBoxID) { 
        if (document.getElementById("chkA" + col + rowIndex).checked == true) { 
         $("#chkA" + col + rowIndex).attr("checked", true); 
         arrA[rowIndex] = col; 
         continue; 
        } 
        else 
         arrA[rowIndex] = 0 
       } 
       $("#chkA" + col + rowIndex).attr("checked", false); 
      } 
      document.getElementById("hidRateA").value = arrA.join(); 
      // alert(document.getElementById("hidRateA").value); 
     } 
    } 

回答

1

该ID将成为C#中强类型标识符。因此,ID不能更改,并且不能包含无效字符。

简单的解决方案是从你的id属性中删除它。

<input type="checkbox" runat="server" id="chkA1" name="chkAC1" style="width: 17px; height: 17px;" value="<%# (Container.RecordIndex)%>" onclick="AppoveCheckA(this)" /> 
+0

'id's'正在改变,但在gridview中有很多行,id也相应地改变 – BNN

+0

@coder将访问此输入的代码添加到您的问题中。 – mason

+0

为此添加了代码。 – BNN

相关问题